...

View Full Version : Need help with a simple schema



seventonecoder
10-13-2008, 10:33 PM
Description of attachments:
- xml.txt - my xml document
- xsd.txt - the schema for my xml document
- diagram.jpeg - a visual display of how I want my data stored

I am just starting to study XML and have run into a small roadblock. I created an xml file to store films, books and cds.

For some reason, I don't think that my schema is correct, but I'm not sure what's wrong. I have followed the w3schools tutorials and think I'm doing everything correctly.

Would anyone be willing to take a look and let me know if I'm not understanding something really basic?

Thanks in advance!

oesxyl
10-13-2008, 10:54 PM
Description of attachments:
- xml.txt - my xml document
- xsd.txt - the schema for my xml document
- diagram.jpeg - a visual display of how I want my data stored

I am just starting to study XML and have run into a small roadblock. I created an xml file to store films, books and cds.

For some reason, I don't think that my schema is correct, but I'm not sure what's wrong. I have followed the w3schools tutorials and think I'm doing everything correctly.

Would anyone be willing to take a look and let me know if I'm not understanding something really basic?

Thanks in advance!
this is the schema generated with trang after your xml:


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="media">
<xs:complexType>
<xs:sequence>
<xs:element ref="films"/>
<xs:element ref="books"/>
<xs:element ref="cds"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="films">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="film"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="film">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="director"/>
<xs:element ref="rating"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="director" type="xs:string"/>
<xs:element name="rating" type="xs:NCName"/>
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="book"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="author"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="author" type="xs:string"/>
<xs:element name="cds">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="cd"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="cd">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="artist"/>
<xs:element ref="genre"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="artist" type="xs:string"/>
<xs:element name="genre" type="xs:string"/>
<xs:element name="title" type="xs:string"/>

</xs:schema>


you don't use the w3c schema, mising namespace but use a string type( from w3c schema? or one of your own?)
in rest seems ok but only a application could tell if is really ok or not. :)

best regards

seventonecoder
10-13-2008, 11:47 PM
Thank you for your reply!

The URI I used was ficticious and was just something using my organizations domain name.

Fixing the namespace declaration (I'm still learning about this :o ) as per your example fixed my original problem of the invalid schema root element.

Now I recieve a different error. I should probably tell you what I'm trying to accomplish here....

I am programming in Microsoft Visual FoxPro 9 and am using the XmlAdapter class, anyways when I use the LoadXml function I get the errors as pictured in the attached. I am convinced that there must be something wrong with my schema yet instead of my Visual FoxPro code as I only get the error when I use the xml and schema in my original post.

Thanks again!


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xs:element name="media">
<xs:complexType>
<xs:sequence>
<xs:element name="films">
<xs:complexType>
<xs:sequence>
<xs:element name="film" type="xs:filmType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book" type="xs:bookType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="cds">
<xs:complexType>
<xs:sequence>
<xs:element name="cd" type="xs:cdType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="filmType">
<xs:sequence>
<xs:element name="title" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="director" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="rating" type="xs:string" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="bookType">
<xs:sequence>
<xs:element name="title" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="author" type="xs:string" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="cdType">
<xs:sequence>
<xs:element name="title" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="artist" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="genre" type="xs:string" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>

oesxyl
10-14-2008, 12:09 AM
last time when I work with foxpro was not visual and not owned by microsoft, :)
unfortunately I can't say what's wrong because I have no idea. My guess is that is a problem with some xpath expression.
the attributes names must match with what you have in test.xsd.

in second pictures you have @name = 'cd' and must be @name = 'cdType'. Also there is a 'cds' there, that could be wrong
sorry, I'm wrong I miss that both 'cd' and 'cds' are in your file
best regards

oesxyl
10-14-2008, 12:22 AM
I don't know if this could change something but try to replace "'" with &apos; in your xml file.
If ms don't change the meaning of an adapter there must be a way to serialize the data and save the schema of a table/database so you can try first to create the database/table in foxpro and then to get the xml and schema and see the difference with what you done.( just ignore if what I said is stupid, :) )

best regards
.

seventonecoder
10-14-2008, 10:35 PM
I'll give it a try. Thanks again for your time and assistance with this.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum