Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursion in xsd

Status
Not open for further replies.

geowalk

Programmer
Mar 12, 2009
1
US
I am having a hard time figuring out just what needs to be done in an XML schema document to allow for a recursive structure that I need to use. I need to build tree components from XML that looks like this:
<trees>
<tree name="treeA">
<node name="name1" icon="icon.jpg">
<node name="name2" icon="icon.jpg">
<foo name="foo1" width="100"/>
<foo name="foo2" width="100"/>
<foo name="foo3" width="100"/>
<node name="name3" icon="icon.jpg"/>
</node>
</node>
</tree>
<tree name="treeB">
...
</tree>
</trees>

The XML file can contain descriptions of many trees, a tree has nodes, nodes can have nodes and/or foos, and all nodes and foos have attributes. I have found a few examples of recursive xsd code by searching, but they don't seem to validate.

Any help would be appreaciated.
Thanks in advance.
 
>nodes can have nodes and/or foos
You can only if you impose an order on the foos and nodes, otherwise it would be out of the scope of w3 schema language.

Suppose all foo(s) should preceed node(s), it looks like this for node.
[tt]
<xs:element name="node">
<xs:complexType>
<xs:sequence>
<xs:element ref="foo" minOccurs="0" maxOccurs="unbounded" />
<xs:element ref="node" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="name" type="xs:token" use="required" />
<xs:attribute name="icon" type="xs:anyURI" use="required" />
</xs:complexType>
</xs:element>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top