| Home » Archived » XML Schema Definition (XSD) » using the prefix of the qname to identify namespaces
 Goto Forum:| 
| using the prefix of the qname to identify namespaces [message #57322] | Tue, 08 February 2005 01:10  |  | 
| Eclipse User  |  |  |  |  | I'm trying to process xsd files whose schema element contains imports. 
 What I want to do is identify each target namespace with it's prefix for
 the purpose of naming my internal data structures.  I need to do this
 before I process the body of the schema, as this affects how I name
 components of the schema.  I need to do this for all of the types,
 elements, etc defined in the schema and in the imported schemas.
 
 For the schema that I'm directly importing, this is no problem, as I
 process the attributes on the xsd:schema element and can get the prefix
 value for each namespace URI (of course I'm not considering the case
 where the namespace prefix/URI is defined on the non-schema element, but
 I'm not worried about that for the time being).
 
 Since imports are resolved only on demand, I can't see how I can process
 the imports before I process the body of the schema (the elements, types
 etc).
 
 What I (think I) want to do is force the resolution of each of the
 imports and then reach into the imported document to grab it's
 prefix/namespace URI definitions.
 
 Is there a way to do this?
 
 Thanks,
 
 Francis
 |  |  |  |  | 
| Re: using the prefix of the qname to identify namespaces [message #57348 is a reply to message #57322] | Tue, 08 February 2005 06:21   |  | 
| Eclipse User  |  |  |  |  | Originally posted by: merks.ca.ibm.com 
 This is a multi-part message in MIME format.
 --------------080002040008070703030105
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Francis,
 
 The XSDEcoreBuilder forces imports to resolve like this:
 
 protected void validate(XSDSchema xsdSchema)
 {
 for (Iterator i = xsdSchema.getContents().iterator(); i.hasNext(); )
 {
 Object content = i.next();
 if (content instanceof XSDImport)
 {
 XSDImport xsdImport = (XSDImport)content;
 xsdImport.resolveTypeDefinition(xsdImport.getNamespace(), "");
 }
 }
 
 But this is only to force imports to resolve that otherwise wouldn't
 resolve because they aren't used.   All the used imports will already be
 resolved by the time an instance of an XSDSchema has been loaded.
 Remember too that a schema can be defined across multiple included files
 and each file may use a different prefix for the target namespace.
 
 
 Francis Upton wrote:
 
 > I'm trying to process xsd files whose schema element contains imports.
 >
 > What I want to do is identify each target namespace with it's prefix
 > for the purpose of naming my internal data structures.  I need to do
 > this before I process the body of the schema, as this affects how I
 > name components of the schema.  I need to do this for all of the
 > types, elements, etc defined in the schema and in the imported schemas.
 >
 > For the schema that I'm directly importing, this is no problem, as I
 > process the attributes on the xsd:schema element and can get the
 > prefix value for each namespace URI (of course I'm not considering the
 > case where the namespace prefix/URI is defined on the non-schema
 > element, but I'm not worried about that for the time being).
 >
 > Since imports are resolved only on demand, I can't see how I can
 > process the imports before I process the body of the schema (the
 > elements, types etc).
 >
 > What I (think I) want to do is force the resolution of each of the
 > imports and then reach into the imported document to grab it's
 > prefix/namespace URI definitions.
 >
 > Is there a way to do this?
 >
 > Thanks,
 >
 > Francis
 
 
 
 --------------080002040008070703030105
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
 </head>
 <body bgcolor="#ffffff" text="#000000">
 Francis,<br>
 <br>
 The XSDEcoreBuilder forces imports to resolve like this:<br>
 <blockquote>  protected void validate(XSDSchema xsdSchema)<br>
   {<br>
     for (Iterator i = xsdSchema.getContents().iterator(); i.hasNext(); )<br>
     {<br>
       Object content = i.next();<br>
       if (content instanceof XSDImport)<br>
       {<br>
          XSDImport xsdImport = (XSDImport)content;<br>
          xsdImport.resolveTypeDefinition(xsdImport.getNamespace(), "");<br>
       }<br>
     }<br>
 </blockquote>
 But this is only to force imports to resolve that otherwise wouldn't
 resolve because they aren't used.   All the used imports will already
 be resolved by the time an instance of an XSDSchema has been loaded. 
 Remember too that a schema can be defined across multiple included
 files and each file may use a different prefix for the target namespace.<br>
 <br>
 <br>
 Francis Upton wrote:
 <blockquote cite="midcu9l4o$ho5$1@www.eclipse.org" type="cite">I'm
 trying to process xsd files whose schema element contains imports.
 <br>
 <br>
 What I want to do is identify each target namespace with it's prefix
 for the purpose of naming my internal data structures.  I need to do
 this before I process the body of the schema, as this affects how I
 name components of the schema.  I need to do this for all of the types,
 elements, etc defined in the schema and in the imported schemas.
 <br>
 <br>
 For the schema that I'm directly importing, this is no problem, as I
 process the attributes on the xsd:schema element and can get the prefix
 value for each namespace URI (of course I'm not considering the case
 where the namespace prefix/URI is defined on the non-schema element,
 but I'm not worried about that for the time being).
 <br>
 <br>
 Since imports are resolved only on demand, I can't see how I can
 process the imports before I process the body of the schema (the
 elements, types etc).
 <br>
 <br>
 What I (think I) want to do is force the resolution of each of the
 imports and then reach into the imported document to grab it's
 prefix/namespace URI definitions.
 <br>
 <br>
 Is there a way to do this?
 <br>
 <br>
 Thanks,
 <br>
 <br>
 Francis
 <br>
 </blockquote>
 <br>
 </body>
 </html>
 
 --------------080002040008070703030105--
 |  |  |  |  | 
| Re: using the prefix of the qname to identify namespaces [message #57373 is a reply to message #57348] | Tue, 08 February 2005 10:11   |  | 
| Eclipse User  |  |  |  |  | Thanks Ed, I think I might made been barking up the wrong tree a little. Since all of the imports have been resolved, I really don't need to
 force their resolution.
 
 So my question is, how do I get to the elements of the imported
 document?  I want to process any xmlns attributes to get the namespace
 prefixes (and yes, I do understand that there might be multiple prefixes
 defined for the same name, but this does not matter as I just need to
 pick one).
 
 Thanks,
 
 Francis
 
 Ed Merks wrote:
 > Francis,
 >
 > The XSDEcoreBuilder forces imports to resolve like this:
 >
 >       protected void validate(XSDSchema xsdSchema)
 >       {
 >         for (Iterator i = xsdSchema.getContents().iterator(); i.hasNext(); )
 >         {
 >           Object content = i.next();
 >           if (content instanceof XSDImport)
 >           {
 >             XSDImport xsdImport = (XSDImport)content;
 >             xsdImport.resolveTypeDefinition(xsdImport.getNamespace(), "");
 >           }
 >         }
 >
 > But this is only to force imports to resolve that otherwise wouldn't
 > resolve because they aren't used.   All the used imports will already be
 > resolved by the time an instance of an XSDSchema has been loaded.
 > Remember too that a schema can be defined across multiple included files
 > and each file may use a different prefix for the target namespace.
 >
 >
 > Francis Upton wrote:
 >
 >> I'm trying to process xsd files whose schema element contains imports.
 >>
 >> What I want to do is identify each target namespace with it's prefix
 >> for the purpose of naming my internal data structures.  I need to do
 >> this before I process the body of the schema, as this affects how I
 >> name components of the schema.  I need to do this for all of the
 >> types, elements, etc defined in the schema and in the imported schemas.
 >>
 >> For the schema that I'm directly importing, this is no problem, as I
 >> process the attributes on the xsd:schema element and can get the
 >> prefix value for each namespace URI (of course I'm not considering the
 >> case where the namespace prefix/URI is defined on the non-schema
 >> element, but I'm not worried about that for the time being).
 >>
 >> Since imports are resolved only on demand, I can't see how I can
 >> process the imports before I process the body of the schema (the
 >> elements, types etc).
 >>
 >> What I (think I) want to do is force the resolution of each of the
 >> imports and then reach into the imported document to grab it's
 >> prefix/namespace URI definitions.
 >>
 >> Is there a way to do this?
 >>
 >> Thanks,
 >>
 >> Francis
 >
 >
 |  |  |  |  | 
| Re: using the prefix of the qname to identify namespaces [message #57397 is a reply to message #57373] | Tue, 08 February 2005 10:28   |  | 
| Eclipse User  |  |  |  |  | Originally posted by: merks.ca.ibm.com 
 This is a multi-part message in MIME format.
 --------------020707020709060000060402
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Francis,
 
 Something like this should do the trick:
 
 XSDSchema xsdSchema = xsdImport.getResolvedSchema();
 String prefix =
 XSDConstants.lookupQualifier(xsdSchema.getElement(),
 xsdSchema.getTargetNamespace());
 
 Note that prefix may be null, i.e., no xmlns is declared, a null string,
 i.e., xmlns="<targetNamespace>", or an non-empty string, i.e.,
 xmlns:xyz="<targetNamespace>".
 
 
 Francis Upton wrote:
 
 > Thanks Ed, I think I might made been barking up the wrong tree a
 > little.  Since all of the imports have been resolved, I really don't
 > need to force their resolution.
 >
 > So my question is, how do I get to the elements of the imported
 > document?  I want to process any xmlns attributes to get the namespace
 > prefixes (and yes, I do understand that there might be multiple
 > prefixes defined for the same name, but this does not matter as I just
 > need to pick one).
 >
 > Thanks,
 >
 > Francis
 >
 > Ed Merks wrote:
 >
 >> Francis,
 >>
 >> The XSDEcoreBuilder forces imports to resolve like this:
 >>
 >>       protected void validate(XSDSchema xsdSchema)
 >>       {
 >>         for (Iterator i = xsdSchema.getContents().iterator();
 >> i.hasNext(); )
 >>         {
 >>           Object content = i.next();
 >>           if (content instanceof XSDImport)
 >>           {
 >>             XSDImport xsdImport = (XSDImport)content;
 >>             xsdImport.resolveTypeDefinition(xsdImport.getNamespace(),
 >> "");
 >>           }
 >>         }
 >>
 >> But this is only to force imports to resolve that otherwise wouldn't
 >> resolve because they aren't used.   All the used imports will already
 >> be resolved by the time an instance of an XSDSchema has been loaded.
 >> Remember too that a schema can be defined across multiple included
 >> files and each file may use a different prefix for the target namespace.
 >>
 >>
 >> Francis Upton wrote:
 >>
 >>> I'm trying to process xsd files whose schema element contains imports.
 >>>
 >>> What I want to do is identify each target namespace with it's prefix
 >>> for the purpose of naming my internal data structures.  I need to do
 >>> this before I process the body of the schema, as this affects how I
 >>> name components of the schema.  I need to do this for all of the
 >>> types, elements, etc defined in the schema and in the imported schemas.
 >>>
 >>> For the schema that I'm directly importing, this is no problem, as I
 >>> process the attributes on the xsd:schema element and can get the
 >>> prefix value for each namespace URI (of course I'm not considering
 >>> the case where the namespace prefix/URI is defined on the non-schema
 >>> element, but I'm not worried about that for the time being).
 >>>
 >>> Since imports are resolved only on demand, I can't see how I can
 >>> process the imports before I process the body of the schema (the
 >>> elements, types etc).
 >>>
 >>> What I (think I) want to do is force the resolution of each of the
 >>> imports and then reach into the imported document to grab it's
 >>> prefix/namespace URI definitions.
 >>>
 >>> Is there a way to do this?
 >>>
 >>> Thanks,
 >>>
 >>> Francis
 >>
 >>
 >>
 
 
 --------------020707020709060000060402
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
 </head>
 <body bgcolor="#ffffff" text="#000000">
 Francis,<br>
 <br>
 Something like this should do the trick:<br>
 <blockquote>  XSDSchema xsdSchema = xsdImport.getResolvedSchema();<br>
   String prefix = XSDConstants.lookupQualifier(xsdSchema.getElement(),
 xsdSchema.getTargetNamespace());<br>
 </blockquote>
 Note that prefix may be null, i.e., no xmlns is declared, a null
 string, i.e., xmlns="<targetNamespace>", or an non-empty string,
 i.e., xmlns:xyz="<targetNamespace>".<br>
 <br>
 <br>
 Francis Upton wrote:
 <blockquote cite="midcuakrs$2lc$1@www.eclipse.org" type="cite">Thanks
 Ed, I think I might made been barking up the wrong tree a little.
  Since all of the imports have been resolved, I really don't need to
 force their resolution.
 <br>
 <br>
 So my question is, how do I get to the elements of the imported
 document?  I want to process any xmlns attributes to get the namespace
 prefixes (and yes, I do understand that there might be multiple
 prefixes defined for the same name, but this does not matter as I just
 need to pick one).
 <br>
 <br>
 Thanks,
 <br>
 <br>
 Francis
 <br>
 <br>
 Ed Merks wrote:
 <br>
 <blockquote type="cite">Francis,
 <br>
 <br>
 The XSDEcoreBuilder forces imports to resolve like this:
 <br>
 <br>
       protected void validate(XSDSchema xsdSchema)
 <br>
       {
 <br>
          for (Iterator i = xsdSchema.getContents().iterator();
 i.hasNext(); )
 <br>
          {
 <br>
            Object content = i.next();
 <br>
            if (content instanceof XSDImport)
 <br>
            {
 <br>
              XSDImport xsdImport = (XSDImport)content;
 <br>
              xsdImport.resolveTypeDefinition(xsdImport.getNamespace(),
 "");
 <br>
            }
 <br>
          }
 <br>
 <br>
 But this is only to force imports to resolve that otherwise wouldn't
 resolve because they aren't used.   All the used imports will already
 be resolved by the time an instance of an XSDSchema has been loaded. 
 Remember too that a schema can be defined across multiple included
 files and each file may use a different prefix for the target
 namespace.
 <br>
 <br>
 <br>
 Francis Upton wrote:
 <br>
 <br>
 <blockquote type="cite">I'm trying to process xsd files whose
 schema element contains imports.
 <br>
 <br>
 What I want to do is identify each target namespace with it's prefix
 for the purpose of naming my internal data structures.  I need to do
 this before I process the body of the schema, as this affects how I
 name components of the schema.  I need to do this for all of the types,
 elements, etc defined in the schema and in the imported schemas.
 <br>
 <br>
 For the schema that I'm directly importing, this is no problem, as I
 process the attributes on the xsd:schema element and can get the prefix
 value for each namespace URI (of course I'm not considering the case
 where the namespace prefix/URI is defined on the non-schema element,
 but I'm not worried about that for the time being).
 <br>
 <br>
 Since imports are resolved only on demand, I can't see how I can
 process the imports before I process the body of the schema (the
 elements, types etc).
 <br>
 <br>
 What I (think I) want to do is force the resolution of each of the
 imports and then reach into the imported document to grab it's
 prefix/namespace URI definitions.
 <br>
 <br>
 Is there a way to do this?
 <br>
 <br>
 Thanks,
 <br>
 <br>
 Francis
 <br>
 </blockquote>
 <br>
 <br>
 </blockquote>
 </blockquote>
 <br>
 </body>
 </html>
 
 --------------020707020709060000060402--
 |  |  |  |  | 
| Re: using the prefix of the qname to identify namespaces [message #57422 is a reply to message #57397] | Wed, 09 February 2005 17:50  |  | 
| Eclipse User  |  |  |  |  | Thanks Ed, this is exactly what I needed.  I'm importing complex schemas and it's handy to be able to identify their parts with the prefix (which
 of course refers to the NS URI).  Even if the prefixes are used
 inconsistently between the files, it's still more convenient to just
 pick one and use that to identify the full NS.
 
 Also, just want to say how much I appreciate using your XSD stuff.  It's
 amazingly solid and very well thought out and organized.  I have not
 found any problems with it at all.  And a personal thanks to you for the
 support you have been doing on this newsgroup.  It's always very helpful.
 
 Best,
 
 Francis
 
 Ed Merks wrote:
 > Francis,
 >
 > Something like this should do the trick:
 >
 >       XSDSchema xsdSchema = xsdImport.getResolvedSchema();
 >       String prefix =
 >     XSDConstants.lookupQualifier(xsdSchema.getElement(),
 >     xsdSchema.getTargetNamespace());
 >
 > Note that prefix may be null, i.e., no xmlns is declared, a null string,
 > i.e., xmlns="<targetNamespace>", or an non-empty string, i.e.,
 > xmlns:xyz="<targetNamespace>".
 >
 >
 > Francis Upton wrote:
 >
 >> Thanks Ed, I think I might made been barking up the wrong tree a
 >> little.  Since all of the imports have been resolved, I really don't
 >> need to force their resolution.
 >>
 >> So my question is, how do I get to the elements of the imported
 >> document?  I want to process any xmlns attributes to get the namespace
 >> prefixes (and yes, I do understand that there might be multiple
 >> prefixes defined for the same name, but this does not matter as I just
 >> need to pick one).
 >>
 >> Thanks,
 >>
 >> Francis
 >>
 >> Ed Merks wrote:
 >>
 >>> Francis,
 >>>
 >>> The XSDEcoreBuilder forces imports to resolve like this:
 >>>
 >>>       protected void validate(XSDSchema xsdSchema)
 >>>       {
 >>>         for (Iterator i = xsdSchema.getContents().iterator();
 >>> i.hasNext(); )
 >>>         {
 >>>           Object content = i.next();
 >>>           if (content instanceof XSDImport)
 >>>           {
 >>>             XSDImport xsdImport = (XSDImport)content;
 >>>             xsdImport.resolveTypeDefinition(xsdImport.getNamespace(),
 >>> "");
 >>>           }
 >>>         }
 >>>
 >>> But this is only to force imports to resolve that otherwise wouldn't
 >>> resolve because they aren't used.   All the used imports will already
 >>> be resolved by the time an instance of an XSDSchema has been loaded.
 >>> Remember too that a schema can be defined across multiple included
 >>> files and each file may use a different prefix for the target namespace.
 >>>
 >>>
 >>> Francis Upton wrote:
 >>>
 >>>> I'm trying to process xsd files whose schema element contains imports.
 >>>>
 >>>> What I want to do is identify each target namespace with it's prefix
 >>>> for the purpose of naming my internal data structures.  I need to do
 >>>> this before I process the body of the schema, as this affects how I
 >>>> name components of the schema.  I need to do this for all of the
 >>>> types, elements, etc defined in the schema and in the imported schemas.
 >>>>
 >>>> For the schema that I'm directly importing, this is no problem, as I
 >>>> process the attributes on the xsd:schema element and can get the
 >>>> prefix value for each namespace URI (of course I'm not considering
 >>>> the case where the namespace prefix/URI is defined on the non-schema
 >>>> element, but I'm not worried about that for the time being).
 >>>>
 >>>> Since imports are resolved only on demand, I can't see how I can
 >>>> process the imports before I process the body of the schema (the
 >>>> elements, types etc).
 >>>>
 >>>> What I (think I) want to do is force the resolution of each of the
 >>>> imports and then reach into the imported document to grab it's
 >>>> prefix/namespace URI definitions.
 >>>>
 >>>> Is there a way to do this?
 >>>>
 >>>> Thanks,
 >>>>
 >>>> Francis
 >>>
 >>>
 >>>
 >
 |  |  |  |  | 
| Re: using the prefix of the qname to identify namespaces [message #593731 is a reply to message #57322] | Tue, 08 February 2005 06:21  |  | 
| Eclipse User  |  |  |  |  | This is a multi-part message in MIME format. --------------080002040008070703030105
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Francis,
 
 The XSDEcoreBuilder forces imports to resolve like this:
 
 protected void validate(XSDSchema xsdSchema)
 {
 for (Iterator i = xsdSchema.getContents().iterator(); i.hasNext(); )
 {
 Object content = i.next();
 if (content instanceof XSDImport)
 {
 XSDImport xsdImport = (XSDImport)content;
 xsdImport.resolveTypeDefinition(xsdImport.getNamespace(), "");
 }
 }
 
 But this is only to force imports to resolve that otherwise wouldn't
 resolve because they aren't used.   All the used imports will already be
 resolved by the time an instance of an XSDSchema has been loaded.
 Remember too that a schema can be defined across multiple included files
 and each file may use a different prefix for the target namespace.
 
 
 Francis Upton wrote:
 
 > I'm trying to process xsd files whose schema element contains imports.
 >
 > What I want to do is identify each target namespace with it's prefix
 > for the purpose of naming my internal data structures.  I need to do
 > this before I process the body of the schema, as this affects how I
 > name components of the schema.  I need to do this for all of the
 > types, elements, etc defined in the schema and in the imported schemas.
 >
 > For the schema that I'm directly importing, this is no problem, as I
 > process the attributes on the xsd:schema element and can get the
 > prefix value for each namespace URI (of course I'm not considering the
 > case where the namespace prefix/URI is defined on the non-schema
 > element, but I'm not worried about that for the time being).
 >
 > Since imports are resolved only on demand, I can't see how I can
 > process the imports before I process the body of the schema (the
 > elements, types etc).
 >
 > What I (think I) want to do is force the resolution of each of the
 > imports and then reach into the imported document to grab it's
 > prefix/namespace URI definitions.
 >
 > Is there a way to do this?
 >
 > Thanks,
 >
 > Francis
 
 
 
 --------------080002040008070703030105
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
 </head>
 <body bgcolor="#ffffff" text="#000000">
 Francis,<br>
 <br>
 The XSDEcoreBuilder forces imports to resolve like this:<br>
 <blockquote>  protected void validate(XSDSchema xsdSchema)<br>
   {<br>
     for (Iterator i = xsdSchema.getContents().iterator(); i.hasNext(); )<br>
     {<br>
       Object content = i.next();<br>
       if (content instanceof XSDImport)<br>
       {<br>
          XSDImport xsdImport = (XSDImport)content;<br>
          xsdImport.resolveTypeDefinition(xsdImport.getNamespace(), "");<br>
       }<br>
     }<br>
 </blockquote>
 But this is only to force imports to resolve that otherwise wouldn't
 resolve because they aren't used.   All the used imports will already
 be resolved by the time an instance of an XSDSchema has been loaded. 
 Remember too that a schema can be defined across multiple included
 files and each file may use a different prefix for the target namespace.<br>
 <br>
 <br>
 Francis Upton wrote:
 <blockquote cite="midcu9l4o$ho5$1@www.eclipse.org" type="cite">I'm
 trying to process xsd files whose schema element contains imports.
 <br>
 <br>
 What I want to do is identify each target namespace with it's prefix
 for the purpose of naming my internal data structures.  I need to do
 this before I process the body of the schema, as this affects how I
 name components of the schema.  I need to do this for all of the types,
 elements, etc defined in the schema and in the imported schemas.
 <br>
 <br>
 For the schema that I'm directly importing, this is no problem, as I
 process the attributes on the xsd:schema element and can get the prefix
 value for each namespace URI (of course I'm not considering the case
 where the namespace prefix/URI is defined on the non-schema element,
 but I'm not worried about that for the time being).
 <br>
 <br>
 Since imports are resolved only on demand, I can't see how I can
 process the imports before I process the body of the schema (the
 elements, types etc).
 <br>
 <br>
 What I (think I) want to do is force the resolution of each of the
 imports and then reach into the imported document to grab it's
 prefix/namespace URI definitions.
 <br>
 <br>
 Is there a way to do this?
 <br>
 <br>
 Thanks,
 <br>
 <br>
 Francis
 <br>
 </blockquote>
 <br>
 </body>
 </html>
 
 --------------080002040008070703030105--
 |  |  |  |  | 
| Re: using the prefix of the qname to identify namespaces [message #593747 is a reply to message #57348] | Tue, 08 February 2005 10:11  |  | 
| Eclipse User  |  |  |  |  | Thanks Ed, I think I might made been barking up the wrong tree a little. Since all of the imports have been resolved, I really don't need to
 force their resolution.
 
 So my question is, how do I get to the elements of the imported
 document?  I want to process any xmlns attributes to get the namespace
 prefixes (and yes, I do understand that there might be multiple prefixes
 defined for the same name, but this does not matter as I just need to
 pick one).
 
 Thanks,
 
 Francis
 
 Ed Merks wrote:
 > Francis,
 >
 > The XSDEcoreBuilder forces imports to resolve like this:
 >
 >       protected void validate(XSDSchema xsdSchema)
 >       {
 >         for (Iterator i = xsdSchema.getContents().iterator(); i.hasNext(); )
 >         {
 >           Object content = i.next();
 >           if (content instanceof XSDImport)
 >           {
 >             XSDImport xsdImport = (XSDImport)content;
 >             xsdImport.resolveTypeDefinition(xsdImport.getNamespace(), "");
 >           }
 >         }
 >
 > But this is only to force imports to resolve that otherwise wouldn't
 > resolve because they aren't used.   All the used imports will already be
 > resolved by the time an instance of an XSDSchema has been loaded.
 > Remember too that a schema can be defined across multiple included files
 > and each file may use a different prefix for the target namespace.
 >
 >
 > Francis Upton wrote:
 >
 >> I'm trying to process xsd files whose schema element contains imports.
 >>
 >> What I want to do is identify each target namespace with it's prefix
 >> for the purpose of naming my internal data structures.  I need to do
 >> this before I process the body of the schema, as this affects how I
 >> name components of the schema.  I need to do this for all of the
 >> types, elements, etc defined in the schema and in the imported schemas.
 >>
 >> For the schema that I'm directly importing, this is no problem, as I
 >> process the attributes on the xsd:schema element and can get the
 >> prefix value for each namespace URI (of course I'm not considering the
 >> case where the namespace prefix/URI is defined on the non-schema
 >> element, but I'm not worried about that for the time being).
 >>
 >> Since imports are resolved only on demand, I can't see how I can
 >> process the imports before I process the body of the schema (the
 >> elements, types etc).
 >>
 >> What I (think I) want to do is force the resolution of each of the
 >> imports and then reach into the imported document to grab it's
 >> prefix/namespace URI definitions.
 >>
 >> Is there a way to do this?
 >>
 >> Thanks,
 >>
 >> Francis
 >
 >
 |  |  |  |  | 
| Re: using the prefix of the qname to identify namespaces [message #593762 is a reply to message #57373] | Tue, 08 February 2005 10:28  |  | 
| Eclipse User  |  |  |  |  | This is a multi-part message in MIME format. --------------020707020709060000060402
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Francis,
 
 Something like this should do the trick:
 
 XSDSchema xsdSchema = xsdImport.getResolvedSchema();
 String prefix =
 XSDConstants.lookupQualifier(xsdSchema.getElement(),
 xsdSchema.getTargetNamespace());
 
 Note that prefix may be null, i.e., no xmlns is declared, a null string,
 i.e., xmlns="<targetNamespace>", or an non-empty string, i.e.,
 xmlns:xyz="<targetNamespace>".
 
 
 Francis Upton wrote:
 
 > Thanks Ed, I think I might made been barking up the wrong tree a
 > little.  Since all of the imports have been resolved, I really don't
 > need to force their resolution.
 >
 > So my question is, how do I get to the elements of the imported
 > document?  I want to process any xmlns attributes to get the namespace
 > prefixes (and yes, I do understand that there might be multiple
 > prefixes defined for the same name, but this does not matter as I just
 > need to pick one).
 >
 > Thanks,
 >
 > Francis
 >
 > Ed Merks wrote:
 >
 >> Francis,
 >>
 >> The XSDEcoreBuilder forces imports to resolve like this:
 >>
 >>       protected void validate(XSDSchema xsdSchema)
 >>       {
 >>         for (Iterator i = xsdSchema.getContents().iterator();
 >> i.hasNext(); )
 >>         {
 >>           Object content = i.next();
 >>           if (content instanceof XSDImport)
 >>           {
 >>             XSDImport xsdImport = (XSDImport)content;
 >>             xsdImport.resolveTypeDefinition(xsdImport.getNamespace(),
 >> "");
 >>           }
 >>         }
 >>
 >> But this is only to force imports to resolve that otherwise wouldn't
 >> resolve because they aren't used.   All the used imports will already
 >> be resolved by the time an instance of an XSDSchema has been loaded.
 >> Remember too that a schema can be defined across multiple included
 >> files and each file may use a different prefix for the target namespace.
 >>
 >>
 >> Francis Upton wrote:
 >>
 >>> I'm trying to process xsd files whose schema element contains imports.
 >>>
 >>> What I want to do is identify each target namespace with it's prefix
 >>> for the purpose of naming my internal data structures.  I need to do
 >>> this before I process the body of the schema, as this affects how I
 >>> name components of the schema.  I need to do this for all of the
 >>> types, elements, etc defined in the schema and in the imported schemas.
 >>>
 >>> For the schema that I'm directly importing, this is no problem, as I
 >>> process the attributes on the xsd:schema element and can get the
 >>> prefix value for each namespace URI (of course I'm not considering
 >>> the case where the namespace prefix/URI is defined on the non-schema
 >>> element, but I'm not worried about that for the time being).
 >>>
 >>> Since imports are resolved only on demand, I can't see how I can
 >>> process the imports before I process the body of the schema (the
 >>> elements, types etc).
 >>>
 >>> What I (think I) want to do is force the resolution of each of the
 >>> imports and then reach into the imported document to grab it's
 >>> prefix/namespace URI definitions.
 >>>
 >>> Is there a way to do this?
 >>>
 >>> Thanks,
 >>>
 >>> Francis
 >>
 >>
 >>
 
 
 --------------020707020709060000060402
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
 </head>
 <body bgcolor="#ffffff" text="#000000">
 Francis,<br>
 <br>
 Something like this should do the trick:<br>
 <blockquote>  XSDSchema xsdSchema = xsdImport.getResolvedSchema();<br>
   String prefix = XSDConstants.lookupQualifier(xsdSchema.getElement(),
 xsdSchema.getTargetNamespace());<br>
 </blockquote>
 Note that prefix may be null, i.e., no xmlns is declared, a null
 string, i.e., xmlns="<targetNamespace>", or an non-empty string,
 i.e., xmlns:xyz="<targetNamespace>".<br>
 <br>
 <br>
 Francis Upton wrote:
 <blockquote cite="midcuakrs$2lc$1@www.eclipse.org" type="cite">Thanks
 Ed, I think I might made been barking up the wrong tree a little.
  Since all of the imports have been resolved, I really don't need to
 force their resolution.
 <br>
 <br>
 So my question is, how do I get to the elements of the imported
 document?  I want to process any xmlns attributes to get the namespace
 prefixes (and yes, I do understand that there might be multiple
 prefixes defined for the same name, but this does not matter as I just
 need to pick one).
 <br>
 <br>
 Thanks,
 <br>
 <br>
 Francis
 <br>
 <br>
 Ed Merks wrote:
 <br>
 <blockquote type="cite">Francis,
 <br>
 <br>
 The XSDEcoreBuilder forces imports to resolve like this:
 <br>
 <br>
       protected void validate(XSDSchema xsdSchema)
 <br>
       {
 <br>
          for (Iterator i = xsdSchema.getContents().iterator();
 i.hasNext(); )
 <br>
          {
 <br>
            Object content = i.next();
 <br>
            if (content instanceof XSDImport)
 <br>
            {
 <br>
              XSDImport xsdImport = (XSDImport)content;
 <br>
              xsdImport.resolveTypeDefinition(xsdImport.getNamespace(),
 "");
 <br>
            }
 <br>
          }
 <br>
 <br>
 But this is only to force imports to resolve that otherwise wouldn't
 resolve because they aren't used.   All the used imports will already
 be resolved by the time an instance of an XSDSchema has been loaded. 
 Remember too that a schema can be defined across multiple included
 files and each file may use a different prefix for the target
 namespace.
 <br>
 <br>
 <br>
 Francis Upton wrote:
 <br>
 <br>
 <blockquote type="cite">I'm trying to process xsd files whose
 schema element contains imports.
 <br>
 <br>
 What I want to do is identify each target namespace with it's prefix
 for the purpose of naming my internal data structures.  I need to do
 this before I process the body of the schema, as this affects how I
 name components of the schema.  I need to do this for all of the types,
 elements, etc defined in the schema and in the imported schemas.
 <br>
 <br>
 For the schema that I'm directly importing, this is no problem, as I
 process the attributes on the xsd:schema element and can get the prefix
 value for each namespace URI (of course I'm not considering the case
 where the namespace prefix/URI is defined on the non-schema element,
 but I'm not worried about that for the time being).
 <br>
 <br>
 Since imports are resolved only on demand, I can't see how I can
 process the imports before I process the body of the schema (the
 elements, types etc).
 <br>
 <br>
 What I (think I) want to do is force the resolution of each of the
 imports and then reach into the imported document to grab it's
 prefix/namespace URI definitions.
 <br>
 <br>
 Is there a way to do this?
 <br>
 <br>
 Thanks,
 <br>
 <br>
 Francis
 <br>
 </blockquote>
 <br>
 <br>
 </blockquote>
 </blockquote>
 <br>
 </body>
 </html>
 
 --------------020707020709060000060402--
 |  |  |  |  | 
| Re: using the prefix of the qname to identify namespaces [message #593773 is a reply to message #57397] | Wed, 09 February 2005 17:50  |  | 
| Eclipse User  |  |  |  |  | Thanks Ed, this is exactly what I needed.  I'm importing complex schemas and it's handy to be able to identify their parts with the prefix (which
 of course refers to the NS URI).  Even if the prefixes are used
 inconsistently between the files, it's still more convenient to just
 pick one and use that to identify the full NS.
 
 Also, just want to say how much I appreciate using your XSD stuff.  It's
 amazingly solid and very well thought out and organized.  I have not
 found any problems with it at all.  And a personal thanks to you for the
 support you have been doing on this newsgroup.  It's always very helpful.
 
 Best,
 
 Francis
 
 Ed Merks wrote:
 > Francis,
 >
 > Something like this should do the trick:
 >
 >       XSDSchema xsdSchema = xsdImport.getResolvedSchema();
 >       String prefix =
 >     XSDConstants.lookupQualifier(xsdSchema.getElement(),
 >     xsdSchema.getTargetNamespace());
 >
 > Note that prefix may be null, i.e., no xmlns is declared, a null string,
 > i.e., xmlns="<targetNamespace>", or an non-empty string, i.e.,
 > xmlns:xyz="<targetNamespace>".
 >
 >
 > Francis Upton wrote:
 >
 >> Thanks Ed, I think I might made been barking up the wrong tree a
 >> little.  Since all of the imports have been resolved, I really don't
 >> need to force their resolution.
 >>
 >> So my question is, how do I get to the elements of the imported
 >> document?  I want to process any xmlns attributes to get the namespace
 >> prefixes (and yes, I do understand that there might be multiple
 >> prefixes defined for the same name, but this does not matter as I just
 >> need to pick one).
 >>
 >> Thanks,
 >>
 >> Francis
 >>
 >> Ed Merks wrote:
 >>
 >>> Francis,
 >>>
 >>> The XSDEcoreBuilder forces imports to resolve like this:
 >>>
 >>>       protected void validate(XSDSchema xsdSchema)
 >>>       {
 >>>         for (Iterator i = xsdSchema.getContents().iterator();
 >>> i.hasNext(); )
 >>>         {
 >>>           Object content = i.next();
 >>>           if (content instanceof XSDImport)
 >>>           {
 >>>             XSDImport xsdImport = (XSDImport)content;
 >>>             xsdImport.resolveTypeDefinition(xsdImport.getNamespace(),
 >>> "");
 >>>           }
 >>>         }
 >>>
 >>> But this is only to force imports to resolve that otherwise wouldn't
 >>> resolve because they aren't used.   All the used imports will already
 >>> be resolved by the time an instance of an XSDSchema has been loaded.
 >>> Remember too that a schema can be defined across multiple included
 >>> files and each file may use a different prefix for the target namespace.
 >>>
 >>>
 >>> Francis Upton wrote:
 >>>
 >>>> I'm trying to process xsd files whose schema element contains imports.
 >>>>
 >>>> What I want to do is identify each target namespace with it's prefix
 >>>> for the purpose of naming my internal data structures.  I need to do
 >>>> this before I process the body of the schema, as this affects how I
 >>>> name components of the schema.  I need to do this for all of the
 >>>> types, elements, etc defined in the schema and in the imported schemas.
 >>>>
 >>>> For the schema that I'm directly importing, this is no problem, as I
 >>>> process the attributes on the xsd:schema element and can get the
 >>>> prefix value for each namespace URI (of course I'm not considering
 >>>> the case where the namespace prefix/URI is defined on the non-schema
 >>>> element, but I'm not worried about that for the time being).
 >>>>
 >>>> Since imports are resolved only on demand, I can't see how I can
 >>>> process the imports before I process the body of the schema (the
 >>>> elements, types etc).
 >>>>
 >>>> What I (think I) want to do is force the resolution of each of the
 >>>> imports and then reach into the imported document to grab it's
 >>>> prefix/namespace URI definitions.
 >>>>
 >>>> Is there a way to do this?
 >>>>
 >>>> Thanks,
 >>>>
 >>>> Francis
 >>>
 >>>
 >>>
 >
 |  |  |  | 
 
 
 Current Time: Fri Oct 31 01:15:06 EDT 2025 
 Powered by FUDForum . Page generated in 0.05358 seconds |