By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,718 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,718 IT Pros & Developers. It's quick & easy.

What would be a good schema for this xml file

P: n/a
All I want to do is have a xml file like this
<Entertainment>
<Movie>
<Title>(Title Here)</Title>
<Rating>(Rating Here)</Title>
</Movie>

<Movie>
<Title>(Title Here)</Title>
<Rating>(Rating Here)</Title>
</Movie>

<Movie>
<Title>(Title Here)</Title>
<Rating>(Rating Here)</Title>
</Movie>

<PS2>
<Title>(Title Here)</Title>
<Rating>(Rating Here)</Title>
</PS2>
</Entertainment>

I try something like the schema below but this schema doesn't work.
With this schema it is looking for a xml file like this. I want to be
able to add as many Movie or PS2 elements in any order without errors.

<Entertainment>
<Movie>
<Title>(Title Here)</Title>
<Rating>(Rating Here)</Title>
</Movie>
<PS2>
<Title>(Title Here)</Title>
<Rating>(Rating Here)</Title>
</PS2>
</Entertainment>
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Entertainment" targetNamespace="http://mark/Homepage/"
elementFormDefault="qualified" xmlns="http://mark/Homepage/"
xmlns:mstns="http://mark/Homepage/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Entertainment">
<xs:complexType>
<xs:sequence>
<xs:element name="Movie" type="Information"></xs:element>
<xs:element name="PS2" type="Information" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Information">
<xs:sequence>
<xs:element name="Description" type="xs:string" />
<xs:element name="Genre" type="xs:string" />
<xs:element name="Hardware" type="xs:string" />
<xs:element name="Picture" type="xs:string" />
<xs:element name="Rating" type="xs:positiveInteger" />
<xs:element name="Title" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
co*******@mix-net.net (Mark Constant) writes:
All I want to do is have a xml file like this
[example elided]

I try something like the schema below but this schema doesn't work.
With this schema it is looking for a xml file like this. I want to be
able to add as many Movie or PS2 elements in any order without errors.

[example with single Movie and single PS2 element]

...
<xs:element name="Entertainment">
<xs:complexType>
<xs:sequence>
<xs:element name="Movie" type="Information"></xs:element>
<xs:element name="PS2" type="Information" />
</xs:sequence>
</xs:complexType>
</xs:element>


Here's your problem: you are telling the schema processor that what
you want in an Entertainment element is a sequence consisting of
exactly one Movie element and exactly one PS2 element, in order.

You can use minOccurs and maxOccurs attributes on the xs:sequence or
xs:element elements to specify that more than one element can occur.

If we just specify maxOccurs="unbounded" on the two elements, we allow
any positive number of Movie elements, followed by any positive number
of PS2 elements:

<xs:complexType>
<xs:sequence>
<xs:element name="Movie" type="Information" maxOccurs="unbounded"/>
<xs:element name="PS2" type="Information" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

If you want to allow Entertainment elements without Movie elements
or PS2 elements, you can also add minOccurs="0" to the xs:element
elements.

Since you want to allow the Movie and PS2 elements to occur in any
order, however, you really need to change something else, too. One
way is to allow the sequence to repeat:

<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Movie" type="Information"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="PS2" type="Information"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

Note that since the sequence can repeat, the maxOccurs attributes on
the xs:element elements are no longer necessary and can be removed.

It is probably more usual, however, to express 'any number of Movie or
PS2 elements, in any order' not as a repeating sequence but as a
repeating choice, thus:

<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Movie" type="Information"/>
<xs:element name="PS2" type="Information"/>
</xs:choice>
</xs:complexType>

I hope this helps.

-C. M. Sperberg-McQueen
World Wide Web Consortium

Jul 20 '05 #2

P: n/a
cm****@acm.org (C. M. Sperberg-McQueen) wrote in message news:<m2************@acm.org>...
co*******@mix-net.net (Mark Constant) writes:
All I want to do is have a xml file like this
[example elided]

I try something like the schema below but this schema doesn't work.
With this schema it is looking for a xml file like this. I want to be
able to add as many Movie or PS2 elements in any order without errors.

[example with single Movie and single PS2 element]

...
<xs:element name="Entertainment">
<xs:complexType>
<xs:sequence>
<xs:element name="Movie" type="Information"></xs:element>
<xs:element name="PS2" type="Information" />
</xs:sequence>
</xs:complexType>
</xs:element>


Here's your problem: you are telling the schema processor that what
you want in an Entertainment element is a sequence consisting of
exactly one Movie element and exactly one PS2 element, in order.

You can use minOccurs and maxOccurs attributes on the xs:sequence or
xs:element elements to specify that more than one element can occur.

If we just specify maxOccurs="unbounded" on the two elements, we allow
any positive number of Movie elements, followed by any positive number
of PS2 elements:

<xs:complexType>
<xs:sequence>
<xs:element name="Movie" type="Information" maxOccurs="unbounded"/>
<xs:element name="PS2" type="Information" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

If you want to allow Entertainment elements without Movie elements
or PS2 elements, you can also add minOccurs="0" to the xs:element
elements.

Since you want to allow the Movie and PS2 elements to occur in any
order, however, you really need to change something else, too. One
way is to allow the sequence to repeat:

<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Movie" type="Information"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="PS2" type="Information"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

Note that since the sequence can repeat, the maxOccurs attributes on
the xs:element elements are no longer necessary and can be removed.

It is probably more usual, however, to express 'any number of Movie or
PS2 elements, in any order' not as a repeating sequence but as a
repeating choice, thus:

<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Movie" type="Information"/>
<xs:element name="PS2" type="Information"/>
</xs:choice>
</xs:complexType>

I hope this helps.

-C. M. Sperberg-McQueen
World Wide Web Consortium


That helped a lot thank you.
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.