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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML and XSD

Status
Not open for further replies.

crazyfishpants

Programmer
Mar 30, 2004
18
US
Hi all,

I am trying to create an XSD for an XML file with multiple "unknown" levels. What I mean is that the XML file I am working from has a single root node that contains many nodes of type A. All Nodes of type A can contain additional type A nodes and also type B nodes. These type A nodes can contain more type A nodes and B nodes. And so on... There is no telling how deep the type A nodes can go. How can I capture this in an XSD?

Thanks!

Example of XML file.

<root>
<type a>
<type a>
...
<type b>
<type b>
<type a>
...
 
You will need to define your XSD using "ref" nodes for those elements.

You can't define it "nested" style, since it sounds like you've got some recursion going on.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Could this also be done using named types...

complexType name = typeB
...
complexType

complexType name = typeA minOccurs = 0 maxOccurs = unbounded
...
element type = typeB
complexType

complexType name = root
element type = typeA minOccurs = 0 maxOccurs = unbounded
complexType

element type = root
 
You could use either method. But I find it easier to use references.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Does either method (reference or named types) have benefits over the other?
 
Not really. It just depends on which is easier to read & maintain.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top