Connecting Tech Pros Worldwide Forums | Help | Site Map

Designing a recursive XML schema

Susan Harris
Guest
 
Posts: n/a
#1: Sep 16 '08
I'm looking to define a particular kind of recursive XML Schema. It needs to
describe the following kind of document:

<nodes>
<node>
<name>Node 1</name>
<item/>
</node>
<node>
<name>Node 2</name>
<nodes>
<node>
<item/>
<name>Node 4</name>
</node>
</nodes>
</node>
<node>
<name>Node 3</name>
<item/>
</node>
</nodes>

Key features of this document are:

1) nodes/node nesting can be to any (reasonable) depth.
2) All "node" elements must contain "a name elements " AND ("a nodes
elements " OR "an item elements "). Or, to put it another way, it should not
contain both a "node" and "item", but must have one of them - in addtion to
the name element, which it also must have.
3). "name" elements can come before or after the "nodes" or "item" element
(e.g. be in an xs:all compositor.

Where I'm really struggling is in how to get the name and nodes OR items.
Looks like I need an xs:all with an xs:choice underneath it, but that
doesn't seem to be allowed.

Help?


Stanimir Stamenkov
Guest
 
Posts: n/a
#2: Sep 16 '08

re: Designing a recursive XML schema


Tue, 16 Sep 2008 20:37:42 +0100, /Susan Harris/:

[...]
Quote:
Where I'm really struggling is in how to get the name and nodes OR
items. Looks like I need an xs:all with an xs:choice underneath it, but
that doesn't seem to be allowed.
Does the following content model group suit you?

(((item | nodes), name) | (name, (item | nodes)))

<xs:choice>
<xs:sequence>
<xs:choice>
<xs:element ref="item" />
<xs:element ref="nodes" />
</xs:choice>
<xs:element ref="name" />
</xs:sequence>
<xs:sequence>
<xs:element ref="name" />
<xs:choice>
<xs:element ref="item" />
<xs:element ref="nodes" />
</xs:choice>
</xs:sequence>
</xs:choice>

--
Stanimir
Susan Harris
Guest
 
Posts: n/a
#3: Sep 16 '08

re: Designing a recursive XML schema


Yes, I think I can see how to make that work. Many thanks!

"Stanimir Stamenkov" <s7an10@netscape.netwrote in message
news:gap4ud$mqj$1@registered.motzarella.org...
Quote:
Tue, 16 Sep 2008 20:37:42 +0100, /Susan Harris/:
>
[...]
Quote:
>Where I'm really struggling is in how to get the name and nodes OR items.
>Looks like I need an xs:all with an xs:choice underneath it, but that
>doesn't seem to be allowed.
>
Does the following content model group suit you?
>
(((item | nodes), name) | (name, (item | nodes)))
>
<xs:choice>
<xs:sequence>
<xs:choice>
<xs:element ref="item" />
<xs:element ref="nodes" />
</xs:choice>
<xs:element ref="name" />
</xs:sequence>
<xs:sequence>
<xs:element ref="name" />
<xs:choice>
<xs:element ref="item" />
<xs:element ref="nodes" />
</xs:choice>
</xs:sequence>
</xs:choice>
>
--
Stanimir
Closed Thread