XML Schema Help For a Newbie

H

HugeBob

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>
 
M

Martin Honnen

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>
 
H

HugeBob

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
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top