471,326 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

easy xsd question?

KJ
In an Xml schema: can an element have children which come from another
namespace?

For example, can this be declared in the schema:

<top>
<anotherNamespace:a>
<aThirdNamespace:b>
Hello World
</aThirdNamespace:b>
</anotherNamespace:a>
</top>

How might the xsd look for this?

Aug 12 '05 #1
5 1101
Yes, but you need to have a schema document for each namespace that you
use.

If your "top" element is not in a namespace, your main schema document
would not have a target namespace. It would look roughly like this:

<xs:schema xmlns:anotherNamespace="foo" ...>
<xs:import namespace="anotherNamespace"
schemaLocation=...
<xs:element name="top">
<xs:complexType>
<xs:sequence>
<xs:element ref="anotherNamespace:a"/>
.....

The schema document that declares "a" would import the third namespace,
looking roughly like this:

<xs:schema targetNamespace="foo"
xmlns:anotherNamespace="foo"
xmlns:aThirdNamespace="bar" ...
<xs:import namespace="aThirdNamespace"
schemaLocation=...
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element ref="aThirdNamespace:b"/>
.....

And the third schema document would look like:

<xs:schema targetNamespace="bar"
xmlns:aThirdNamespace="bar" ...
<xs:element name="b">
.....

etc.

Hope that helps,
Priscilla

----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Aug 12 '05 #2
KJ
Thank you. Would you please entertain a further question? I hope I can
word this so it makes sense.

Do the nodes of instance documents of such a schema have to obey the
sequence and other rules of their respective schemas, in addition to
obeying the rules of the schema in which they are included? (Are
parsers smart enough to recognize this kind of thing?)

And, can an schema that imports nodes from change the restrictions set
forth by the imported schema, for example, by reordering sequences, and
so forth?

-KJ

Aug 12 '05 #3
Hi,

I'm not sure I'm entirely following your question. Any given element
would be declared in only one of the schema documents, so its contents
would have to follow the rules that are specified in that one
declaration.

About your second question, No, the importing schema cannot reorder
sequences in types that are in the imported schema document. But you
can create new types in the importing schema document that combine
elements from the other (imported) namespace in different ways.

Hope that helps,
Priscilla
----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Aug 13 '05 #4
KJ
That was pretty much what I was trying to ask. Thanks for answering.
What I need to do now is just try out some of these scenarios to see
how it all works.

-KJ

Aug 15 '05 #5
KJ wrote:
In an Xml schema: can an element have children which come from another
namespace?


Yes, this was one of the original (long-forgotten and never-implemented)
reasons for namspaces in the first place -- to be able to import a subset
of some other DTD or Schema to save you having to reinvent the wheel.

For example, "let me use Lists the way DocBook does them" or "give me
section and heading declarations the way TEI does them".

Increasing modularisation may one day make this possible :-) For now,
it's just as Priscilla describes it.

///Peter
--
sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
&;top"
Aug 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by | last post: by
5 posts views Thread by LedZep | last post: by
1 post views Thread by Mad Scientist Jr | last post: by
13 posts views Thread by Ghislain Tanguay | last post: by
1 post views Thread by melanieab | last post: by
6 posts views Thread by Martin Bootsma | last post: by
27 posts views Thread by smnoff | last post: by
9 posts views Thread by rynTAU | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.