473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

What would be a good schema for this xml file

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
2 1445
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olaf Meyer | last post by:
Apprentently xerces 2.6.0 (Java) does not validate against contraints specified in the schema (e.g. constraints specified via unique element). The validation works with the XML editor I'm using...
0
by: Aaron P Frenger | last post by:
Hello All, I have a very large XML file that I would like to split up into a few smaller files, but still use only one schema. I am using Xerces C++ libraries. My idea is to have one schema...
2
by: pohmart | last post by:
I am using Xerces 2.6.2 and SAX on Windows2k. I want to validate an XML doc, which has no schema reference, with an external schema which is on my PC. I am setting the following properties and...
10
by: wackyphill | last post by:
I know in SQL Server the terms Database and Catalog are used interchangably. But a table is also assigned a schema. As seen in the INFORMATION_SCHEMA.Tables View. I don't get what this schema...
2
by: Vagabond Software | last post by:
I have translated a DTD to an XML Schema (XSD) file by hand, and the Schema View in Visual Studio .NET 2003 seems to diplay everything properly. However, when I specify the schemalocation in my...
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
0
by: Aaron P Frenger | last post by:
Hello All, I have a very large XML file that I would like to split up into a few smaller files, but still use only one schema. I am using Xerces C++ libraries. My idea is to have one schema...
1
by: Szaki | last post by:
I use a BulkLoad to import file.xml to my base MS Server 2000. To import this xml file I need schema file. Mayby you know how to do this file mechanicy f.g. mayby somebody have some script in .net...
4
by: Stan R. | last post by:
Hello, I have xmllint and xsltproc installed and running on both my linux and win32 platforms, all seems good. I have a couple questions though. 1) If I have an external dtd file, which is...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.