XML Schema Help For a Newbie

HugeBob

Usenet Archive
Joined
Aug 1, 2006
Messages
41
Reaction score
0
Hi All,

I have this XML schema and instance that I'm having trouble with. The schema and instance are below. I tried validating the pair. But I get an error saying "Cannot find the declaration of element 'vendor'."

Schema (autos.xsd)

<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:auto="http://www.autos.com/data" targetNamespace="http://www.autos.com/data"> <xs:element name="vendor"> <xs:complexType> <xs:all> <xs:element name="title" type="xs:string"/> <xs:element name="introduction" type="xs:string"/> <xs:element name="advertisement" type="xs:string"/> <xs:element name="auto"> <xs:complexType> <xs:all> <xs:element name="auto_name" type="xs:string"/> <xs:element name="year" type="xs:integer"/> <xs:element name="mileage" type="xs:integer"/> <xs:element name="description" type="xs:string"/> <xs:element name="price" type="xs:decimal"/> </xs:all> </xs:complexType> </xs:element> </xs:all> </xs:complexType> </xs:element> </xs:schema>

Instance (autos.xml)
<?xml version="1.0"?>
<vendor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:auto="http://www.autos.com/data" xsi:schemaLocation="http://www.autos.com/data autos.xsd"> <title>JHU Used Car Sales</title> <introduction>blah, blah, blah</introduction> <advertisement>blah blah blah</advertisement> <auto> <auto_name>Honda Civic</auto_name> <year>1991</year> <mileage>175</mileage> <description>Perfect Condition (Don't mind the rust)</description> <price>1199.00</price> </auto> <auto> <auto_name>Chevy Vega</auto_name> <year>1976</year> <mileage>96</mileage> <description>Overheat occasionally</description> <price>699.00</price> </auto> <auto> <auto_name>Nissan Xterra</auto_name> <year>2004</year> <mileage>14</mileage> <description>Fully loaded</description> <price>22500.00</price> </auto> <auto> <auto_name>Jeep Wrangler</auto_name> <year>2000</year> <mileage>65</mileage> <description>Runs well if its not raining</description> <price>9999.00</price> </auto> <auto> <auto_name>Dodge Charger</auto_name> <year>1986</year> <mileage>110</mileage> <description>Really is a good car, just a bad design</description> <price>899.00</price> </auto> </vendor>
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
HugeBob said:
I have this XML schema and instance that I'm having trouble with. The schema and instance are below. I tried validating the pair. But I get an error saying "Cannot find the declaration of element 'vendor'."

Schema (autos.xsd)

<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:auto="http://www.autos.com/data" targetNamespace="http://www.autos.com/data">

The schema defines its element in its targetNamespace, namely http://www.autos.com/data. You probably want to have elementFormDefault="qualified" too on the xs:schema element.

Then you need to put your instance elements in that namespace


<vendor xmlns="http://www.autos.com/data"> ...
</vendor>
 

HugeBob

Usenet Archive
Joined
Aug 1, 2006
Messages
41
Reaction score
0
The schema defines its element in its targetNamespace, namelyhttp://www.autos.com/data. You probably want to have elementFormDefault="qualified" too on the xs:schema element.

Then you need to put your instance elements in that namespace

   <vendor xmlns="http://www.autos.com/data"> ...
   </vendor>

Martin,

Thanks for your input. After looking at it some more, I was able to get the results I wanted. I had the namespaces entered incorrectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top