Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Newbie question, schema, complex types and unordered multiple elemets

Reply
Thread Tools

Newbie question, schema, complex types and unordered multiple elemets

 
 
davidjones@myself.com
Guest
Posts: n/a
 
      10-16-2007
I want to model a situation where you can have multiple children of an
element, and the children can be different types and in any order. A
simple example of what I mean is at [1]. I am trying to make a schema
to define this document, my attempted schema at [2].

If I understand the format correctly I need to make the parent element
(building) a complex type, and this must have an order indicator to
contain other elements. None of the 3 order indicators (All, Choice,
Sequence) fit my model.

How do I do this? It seems I am missing something fundamental, or I
am trying to model data that cannot be fit to xml.

Thank you for any help.

[1]
<building name="house1">
<window state="open"/>
<door state="open"/>
<door state="closed"/>
<window state="closed"/>
</building>

[2]
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="building">
<xs:annotation>
<xs:documentation>a building</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence> <!-- This tag is the problem -->
<xs:element name="window" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="state" type="xs:string" use="required"/
>

</xs:complexType>
</xs:element>
<xs:element name="door" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="state" type="xs:string" use="required"/
>

</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

 
Reply With Quote
 
 
 
 
usenet@tech-know-ware.com
Guest
Posts: n/a
 
      10-16-2007
On 16 Oct, 14:45, davidjo...@myself.com wrote:
> I want to model a situation where you can have multiple children of an
> element, and the children can be different types and in any order. A
> simple example of what I mean is at [1]. I am trying to make a schema
> to define this document, my attempted schema at [2].
>
> If I understand the format correctly I need to make the parent element
> (building) a complex type, and this must have an order indicator to
> contain other elements. None of the 3 order indicators (All, Choice,
> Sequence) fit my model.
>
> How do I do this? It seems I am missing something fundamental, or I
> am trying to model data that cannot be fit to xml.
>
> Thank you for any help.
>
> [1]
> <building name="house1">
> <window state="open"/>
> <door state="open"/>
> <door state="closed"/>
> <window state="closed"/>
> </building>
>
> [2]
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> <xs:element name="building">
> <xs:annotation>
> <xs:documentation>a building</xs:documentation>
> </xs:annotation>
> <xs:complexType>
> <xs:sequence> <!-- This tag is the problem -->
> <xs:element name="window" maxOccurs="unbounded">
> <xs:complexType>
> <xs:attribute name="state" type="xs:string" use="required"/
>
> </xs:complexType>
> </xs:element>
> <xs:element name="door" maxOccurs="unbounded">
> <xs:complexType>
> <xs:attribute name="state" type="xs:string" use="required"/
>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>


One thing that might work for you is changing the xs:sequence in your
schema to:

<xs:choice maxOccurs="unbounded">...

HTH,

Pete.
=============================================
Pete Cordell
Codalogic
for XML Schema to C++ data binding visit
http://www.codalogic.com/lmx/
=============================================

 
Reply With Quote
 
 
 
 
davidjones@myself.com
Guest
Posts: n/a
 
      10-17-2007
On 16 Oct, 20:11, use...@tech-know-ware.com wrote:
> One thing that might work for you is changing the xs:sequence in your
> schema to:
>
> <xs:choice maxOccurs="unbounded">...


Thanks, that does exactly what I want. It does not seems to do what
w3schools says it does:

from http://www.w3schools.com/schema/sche...indicators.asp

The <choice> indicator specifies that either one child element or
another can occur:

Is there a more accurate description of what these tags really mean?

Thank you for the help.

 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      10-17-2007
> Thanks, that does exactly what I want. It does not seems to do what
> w3schools says it does:


Unfortunately, most of what I've heard about w3schools suggests that it
isn't a particuarly well-organized resource (often not complete,
sometimes not accurate).

Choice says that any of the contained items can occur at this point. The
default if those aren't specified is exactly one instance of the choice,
no more and no less, but the standard Schema attributes such as
maxOccurs can be used to change that.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
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
removing common elemets in a list saif.shakeel@gmail.com Python 6 05-17-2007 08:29 AM
Can XSD simple types be derived from complex types? Soren Kuula XML 2 12-01-2005 07:51 PM
XML Schema 0- unordered set containing multiple occuring element Naresh Agarwal XML 1 03-07-2004 12:39 PM
Re: Newbie...How can I double-space an unordered list spaghetti HTML 3 07-17-2003 02:24 PM
Re: Newbie...How can I double-space an unordered list Jukka K. Korpela HTML 0 07-16-2003 06:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57