K
Kevin Campbell
Say I have the following XML spec:
<Book>
<Title />
<Author />
<ISBN />
<Description />
</Book>
Title, Author, ISBN and Description may appear in any order. Title,
Author and ISBN must appear exactly once, and Description may appear 0
or 1 times. Thus, the following XML is also valid.
<Book>
<Author />
<ISBN />
<Title />
</Book>
I haven't been working with XML schemas for very long, but from what I
have read it seems that it would be fairly difficult to validate this
type of XML using schemas.
I know how to specify an unordered list where all elements are
optional and unbounded:
<xs:complexType name="BookType">
<xs:choice maxOccurs="unbounded">
<xs:element ref="Title"/>
<xs:element ref="Author"/>
<xs:element ref="ISBN"/>
<xs:element ref="Description"/>
</xs:choice>
</xs:complexType>
<xs:element name="Book" type="BookType" />
However, such a schema permits invalid XML such as this:
<Book>
<Title>
<Title>
</Book>
Using the above schema, I could perform further validation in my code,
but I am wondering if there is a way to do it using schema only. It
seems to me that one of the nice benefits of XML as a structured data
format is that element ordering is not necessarily relevant. In my
example the order of the elements has no semantic meaning, so I would
like authors to be able to not worry about ordering while still
gaining the benefits of validated XML.
Does anyone know how to accomplish this using XML Schemas?
Thanks,
Kevin Campbell
<Book>
<Title />
<Author />
<ISBN />
<Description />
</Book>
Title, Author, ISBN and Description may appear in any order. Title,
Author and ISBN must appear exactly once, and Description may appear 0
or 1 times. Thus, the following XML is also valid.
<Book>
<Author />
<ISBN />
<Title />
</Book>
I haven't been working with XML schemas for very long, but from what I
have read it seems that it would be fairly difficult to validate this
type of XML using schemas.
I know how to specify an unordered list where all elements are
optional and unbounded:
<xs:complexType name="BookType">
<xs:choice maxOccurs="unbounded">
<xs:element ref="Title"/>
<xs:element ref="Author"/>
<xs:element ref="ISBN"/>
<xs:element ref="Description"/>
</xs:choice>
</xs:complexType>
<xs:element name="Book" type="BookType" />
However, such a schema permits invalid XML such as this:
<Book>
<Title>
<Title>
</Book>
Using the above schema, I could perform further validation in my code,
but I am wondering if there is a way to do it using schema only. It
seems to me that one of the nice benefits of XML as a structured data
format is that element ordering is not necessarily relevant. In my
example the order of the elements has no semantic meaning, so I would
like authors to be able to not worry about ordering while still
gaining the benefits of validated XML.
Does anyone know how to accomplish this using XML Schemas?
Thanks,
Kevin Campbell