XML Schema Help For a Newbie

Discussion in 'XML' started by HugeBob, Feb 16, 2009.

  1. HugeBob

    HugeBob Guest

    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>
     
    HugeBob, Feb 16, 2009
    #1
    1. Advertising

  2. 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 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:xsi="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/
     
    Martin Honnen, Feb 16, 2009
    #2
    1. Advertising

  3. HugeBob

    HugeBob Guest

    On Feb 16, 10:24 am, Martin Honnen <> 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      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, 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:xsi="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.
     
    HugeBob, Feb 17, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,661
    Markus
    Nov 23, 2005
  2. Fred Smith
    Replies:
    1
    Views:
    996
    Martin Honnen
    Feb 5, 2004
  3. Hari Om
    Replies:
    1
    Views:
    482
    Martin SChukrazy
    Mar 2, 2004
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,325
    Stanimir Stamenkov
    Apr 25, 2005
  5. Replies:
    3
    Views:
    3,169
Loading...

Share This Page