Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using loops in XSD?

Reply
Thread Tools

Using loops in XSD?

 
 
Christian Rühl
Guest
Posts: n/a
 
      11-19-2007
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
 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      11-19-2007

Christian Rühl <(E-Mail Removed)> wrote in
<(E-Mail Removed)>:
> the xml files i want to validate look like this:
>
> - product
> -- component
> --- sub-component
> --- sub-component
> ---- sub-component
> -- component
> --- sub-component
> ---- sub-component


And why, pray tell me, didn't you post an actual XML
document that we would be able to stuff into our parsers?
To make life more interesting for us?

> each (sub-)component can have one or more own
> sub-components and so on...


<xs:schema xmlnss="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>

--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.
 
Reply With Quote
 
 
 
 
Christian Rühl
Guest
Posts: n/a
 
      11-19-2007
On 19 Nov., 14:57, Pavel Lepin <(E-Mail Removed)> wrote:
> Christian Rühl <(E-Mail Removed)> wrote in
> <(E-Mail Removed)>:
>
> > the xml files i want to validate look like this:

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

>
> And why, pray tell me, didn't you post an actual XML
> document that we would be able to stuff into our parsers?
> To make life more interesting for us?
>
> > each (sub-)component can have one or more own
> > sub-components and so on...

>
> <xs:schema xmlnss="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>
>
> --
> ...also, I submit that we all must honourably commit seppuku
> right now rather than serve the Dark Side by producing the
> HTML 5 spec.


wow, that was easy! i should have known that... in fact i've been
working with that a little earlier in another project... maybe i just
don't get enough sleep!
thanks a lot anyway! you helped me before!
 
Reply With Quote
 
usenet@tech-know-ware.com
Guest
Posts: n/a
 
      11-19-2007
On 19 Nov, 14:41, "Christian Rühl" <(E-Mail Removed)> wrote:
> On 19 Nov., 14:57, Pavel Lepin <(E-Mail Removed)> wrote:
> > Christian Rühl <(E-Mail Removed)> wrote in
> > <(E-Mail Removed)>:

>
> > > the xml files i want to validate look like this:
> > > -- component
> > > --- sub-component
> > > --- sub-component
> > > ---- sub-component
> > > -- component
> > > --- sub-component
> > > ---- sub-component

>
> > <xs:schema xmlnss="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 xmlnss="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 xmlnss="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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loops with loops using html-template Me Perl Misc 2 01-12-2006 05:07 PM
using threads with for-loops Klaus Neuner Python 10 10-05-2004 08:34 AM
Easy way to alternate output with XSLT when not using templates or loops? Michael Ahlers XML 3 07-15-2004 02:48 PM
Newbee needs Help ref Using Function Statements not Loops(For) jstreet10 Python 1 12-03-2003 06:27 PM
Using Loops to track user input hokiegal99 Python 9 07-21-2003 02:41 PM



Advertisments