469,645 Members | 1,747 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Using loops in XSD?

hi @all!

i have a little problem with xsd. is it possible to define a loop in a
schema?

the xml files i want to validate look like this:

- product
-- component
--- sub-component
--- sub-component
---- sub-component
-- component
--- sub-component
---- sub-component

each (sub-)component can have one or more own sub-components and so
on... there is a static solution needed because the xml file is
usually written by hand. writing it by using to many references makes
it more likely to make a mistake and more difficult to locate an
error.

i really hope you can help me with that. i didn't find a real hint
yet. :(

Mfg,
Christian Rühl
Nov 19 '07 #1
1 4197
On 19 Nov, 14:41, "Christian Rühl" <ch...@cruehl.comwrote:
On 19 Nov., 14:57, Pavel Lepin <p.le...@ctncorp.comwrote:
Christian Rühl <ch...@cruehl.comwrote in
<72cc99e1-7a7b-4ac3-a346-7f850aa64...@p69g2000hsa.googlegroups.com>:
the xml files i want to validate look like this:
-- component
--- sub-component
--- sub-component
---- sub-component
-- component
--- sub-component
---- sub-component
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sub">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="sub"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Another option might be:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sub">
<xs:complexType>
<xs:sequence>
<!-- You might want some extra stuff here. -->
<xs:element ref="sub" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Or (tweak of Pavel's):

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sub">
<xs:complexType>
<xs:choice>
<xs:element ref="subdetails" type="subdetails"/>
<xs:element ref="sub" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

The difference between the two depends on whether a sub-component with
sub-components _only_ have sub-components, or has other data plus sub-
components. (Wow - that's a lot of sub-components!)

HTH,

Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/
for XML Schema to C++ data binding
Nov 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Kartic | last post: by
17 posts views Thread by John Salerno | last post: by
10 posts views Thread by Putty | last post: by
9 posts views Thread by Nathan Sokalski | last post: by
8 posts views Thread by Nathan Sokalski | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.