Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML Schema Help For a Newbie

Reply
Thread Tools

XML Schema Help For a Newbie

 
 
HugeBob
Guest
Posts: n/a
 
      02-16-2009
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 xmlnss="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 xmlnssi="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>

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-16-2009
HugeBob wrote:

> 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 xmlnss="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 xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:auto="http://www.autos.com/data"
> xsi:schemaLocation="http://www.autos.com/data autos.xsd">


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




--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
HugeBob
Guest
Posts: n/a
 
      02-17-2009
On Feb 16, 10:24*am, Martin Honnen <(E-Mail Removed)> wrote:
> HugeBob wrote:
> > 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 * * *xmlnss="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, 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 xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> > * * * * * * * * * * * * * *xmlns:auto="http://www.autos.com/data"
> > * * * * * * * * * * * * * *xsi:schemaLocation="http://www.autos.com/dataautos.xsd">

>
> * *<vendor xmlns="http://www.autos.com/data">
> * * *...
> * *</vendor>
>
> --
>
> * * * * Martin Honnen
> * * * *http://JavaScript.FAQTs.com/


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.

 
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