easy xsd question?

K

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?
 
P

Priscilla Walmsley

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
 
K

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
 
P

Priscilla Walmsley

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
 
K

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
 
P

Peter Flynn

KJ said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,251
Members
46,851
Latest member
CristineKo

Latest Threads

Top