Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » using the prefix of the qname to identify namespaces
using the prefix of the qname to identify namespaces [message #57322] Tue, 08 February 2005 06:10 Go to next message
Francis Upton IV is currently offline Francis Upton IVFriend
Messages: 472
Registered: July 2009
Location: Oakland, CA
Senior Member
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 11:21 Go to previous messageGo to next message
Eclipse UserFriend
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>&nbsp; protected void validate(XSDSchema xsdSchema)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; for (Iterator i = xsdSchema.getContents().iterator(); i.hasNext(); )<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Object content = i.next();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (content instanceof XSDImport)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; XSDImport xsdImport = (XSDImport)content;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; xsdImport.resolveTypeDefinition(xsdImport.getNamespace(), "");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
</blockquote>
But this is only to force imports to resolve that otherwise wouldn't
resolve because they aren't used.&nbsp;&nbsp; All the used imports will already
be resolved by the time an instance of an XSDSchema has been loaded.&nbsp;
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.&nbsp; I need to do
this before I process the body of the schema, as this affects how I
name components of the schema.&nbsp; 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 15:11 Go to previous messageGo to next message
Francis Upton IV is currently offline Francis Upton IVFriend
Messages: 472
Registered: July 2009
Location: Oakland, CA
Senior Member
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 15:28 Go to previous messageGo to next message
Eclipse UserFriend
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>&nbsp; XSDSchema xsdSchema = xsdImport.getResolvedSchema();<br>
&nbsp; 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="&lt;targetNamespace&gt;", or an non-empty string,
i.e., xmlns:xyz="&lt;targetNamespace&gt;".<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.
&nbsp;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?&nbsp; 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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected void validate(XSDSchema xsdSchema)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; for (Iterator i = xsdSchema.getContents().iterator();
i.hasNext(); )
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Object content = i.next();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (content instanceof XSDImport)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XSDImport xsdImport = (XSDImport)content;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xsdImport.resolveTypeDefinition(xsdImport.getNamespace(),
"");
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
<br>
<br>
But this is only to force imports to resolve that otherwise wouldn't
resolve because they aren't used.&nbsp;&nbsp; All the used imports will already
be resolved by the time an instance of an XSDSchema has been loaded.&nbsp;
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.&nbsp; I need to do
this before I process the body of the schema, as this affects how I
name components of the schema.&nbsp; 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 22:50 Go to previous message
Francis Upton IV is currently offline Francis Upton IVFriend
Messages: 472
Registered: July 2009
Location: Oakland, CA
Senior Member
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 11:21 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
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>&nbsp; protected void validate(XSDSchema xsdSchema)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; for (Iterator i = xsdSchema.getContents().iterator(); i.hasNext(); )<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Object content = i.next();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (content instanceof XSDImport)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; XSDImport xsdImport = (XSDImport)content;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; xsdImport.resolveTypeDefinition(xsdImport.getNamespace(), "");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
</blockquote>
But this is only to force imports to resolve that otherwise wouldn't
resolve because they aren't used.&nbsp;&nbsp; All the used imports will already
be resolved by the time an instance of an XSDSchema has been loaded.&nbsp;
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.&nbsp; I need to do
this before I process the body of the schema, as this affects how I
name components of the schema.&nbsp; 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--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: using the prefix of the qname to identify namespaces [message #593747 is a reply to message #57348] Tue, 08 February 2005 15:11 Go to previous message
Francis Upton IV is currently offline Francis Upton IVFriend
Messages: 472
Registered: July 2009
Location: Oakland, CA
Senior Member
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 15:28 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
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>&nbsp; XSDSchema xsdSchema = xsdImport.getResolvedSchema();<br>
&nbsp; 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="&lt;targetNamespace&gt;", or an non-empty string,
i.e., xmlns:xyz="&lt;targetNamespace&gt;".<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.
&nbsp;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?&nbsp; 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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected void validate(XSDSchema xsdSchema)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; for (Iterator i = xsdSchema.getContents().iterator();
i.hasNext(); )
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Object content = i.next();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (content instanceof XSDImport)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XSDImport xsdImport = (XSDImport)content;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xsdImport.resolveTypeDefinition(xsdImport.getNamespace(),
"");
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
<br>
<br>
But this is only to force imports to resolve that otherwise wouldn't
resolve because they aren't used.&nbsp;&nbsp; All the used imports will already
be resolved by the time an instance of an XSDSchema has been loaded.&nbsp;
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.&nbsp; I need to do
this before I process the body of the schema, as this affects how I
name components of the schema.&nbsp; 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--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: using the prefix of the qname to identify namespaces [message #593773 is a reply to message #57397] Wed, 09 February 2005 22:50 Go to previous message
Francis Upton IV is currently offline Francis Upton IVFriend
Messages: 472
Registered: July 2009
Location: Oakland, CA
Senior Member
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
>>>
>>>
>>>
>


Previous Topic:using the prefix of the qname to identify namespaces
Next Topic:Ecore XML schema mapping
Goto Forum:
  


Current Time: Thu Apr 25 01:14:47 GMT 2024

Powered by FUDForum. Page generated in 0.03641 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top