Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > What would be a good schema for this xml file

Reply
Thread Tools

What would be a good schema for this xml file

 
 
Mark Constant
Guest
Posts: n/a
 
      11-29-2003
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/"
xmlnss="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="xsositiveInteger" />
<xs:element name="Title" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
 
Reply With Quote
 
 
 
 
C. M. Sperberg-McQueen
Guest
Posts: n/a
 
      11-30-2003
(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

 
Reply With Quote
 
 
 
 
Mark Constant
Guest
Posts: n/a
 
      12-01-2003
(C. M. Sperberg-McQueen) wrote in message news:<>...
> (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.
 
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
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema huntingseasonson@gmail.com Perl Misc 5 11-29-2006 12:37 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
XML Schema to XML Schema Conversion Hari Om XML 1 03-02-2004 09:04 PM
XML schema regular expressions question and recommended XML Schema book Fred Smith XML 1 02-05-2004 11:12 AM



Advertisments