2

I know what the error means, but as far as I can see, the Order element is properly declared in the schema. Is it something to do with the way I declare my schema location? I am not sure how to go about fixing the declaration. Any thoughts?

My XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<Order 
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://lolteamrecruiter.com order.xsd">
  <Customer id="n12">Aaron Rodgers</Customer>
  <Product>
    <Name>Old Time Souvenir Football</Name>
    <SKU>244</SKU>
    <Quantity>12</Quantity>
    <Price currency="taco">21.95</Price>
    <ShipTo>
      <Street>135 Airline Highway</Street>
      <City>Green Bay</City> <State>WI</State> <Zip>02882</Zip>
    </ShipTo>
  </Product>
  <Product>
    <Name>Official Packer Football</Name>
    <SKU>256</SKU>
    <Quantity>1</Quantity>
    <Price currency="USD">France</Price>
    <Discount>.10</Discount>
    <ShipTo>
      <GiftRecipient>Gertrude Rodgers</GiftRecipient>
      <Street>271 Old Homestead Way</Street>
      <City>San Francisco</City> <State>CA</State> <Zip>02895</Zip>
    </ShipTo>
    <GiftMessage>Happy Mothers Day to a great Mom! Love, Aaron</GiftMessage>
  </Product> 
  <Subtotal currency='USD'>263.40</Subtotal>
  <Tax rate="7.0" 
       currency='USD'>18.44</Tax>
  <Shipping  method="USPS" currency='USD'>8.95</Shipping>
  <Total currency='USD' >290.79</Total>
</Order>

My XSD

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

<xs:element name="Order">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Customer" type="xs:string">
        <xs:complexType>
            <xs:attribute name="id" type="xs:string"  use="required"/>
        </xs:complexType>
      </xs:element>
      <xs:element name="Product" minOccurs="1" maxOccurs="unbounded">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Name" type="xs:string"/>
                <xs:element name="SKU" type="xs:string"/>
                <xs:element name="Quantity" type="xs:string"/>
                <xs:element name="Price" type="currRestrict">
                    <xs:complexType>
                        <xs:attribute name="currency" type="currencyType" use="required"/>
                    </xs:complexType>               
                </xs:element>
                <xs:element name="Discount" type="xs:string" minOccurs="0" maxOccurs="1"/>
                <xs:element name="ShipTo">
                      <xs:complexType>
                        <xs:sequence>
                            <xs:element name="GiftRecipient" type="xs:string"/>
                            <xs:element name="street" type="xs:string"/>
                            <xs:element name="City" type="xs:string"/>
                            <xs:element name="State" type="xs:decimal"/>
                            <xs:element name="Zip" type="xs:decimal"/>
                        </xs:sequence>
                      </xs:complexType>
                </xs:element>
                <xs:element name="GiftMessage" type="xs:string" minOccurs="0" maxOccurs="1"/>
            </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="Subtotal" type="xs:decimal">
        <xs:complexType>
            <xs:attribute name="currency" type="currencyType" use="required"/>
        </xs:complexType>               
      </xs:element>
       <xs:element name="Tax" type="xs:decimal">
        <xs:complexType>
            <xs:attribute name="currency" type="currencyType" use="required"/>
            <xs:attribute name="rate" type="currencyType"/>
        </xs:complexType>               
      </xs:element>
       <xs:element name="Shipping" type="xs:string">
        <xs:complexType>
            <xs:attribute name="currency" type="currencyType" use="required"/>
            <xs:attribute name="method" type="methodType" default="UPS"/>
        </xs:complexType>               
      </xs:element>
      <xs:element name="Total" type="xs:decimal">
        <xs:complexType>
            <xs:attribute name="currency" type="currencyType" use="required"/>
        </xs:complexType>               
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:simpleType name="currencyType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="USD"/>
      <xs:enumeration value="CAN"/>
      <xs:enumeration value="GBP"/>
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="methodType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="UPS"/>
      <xs:enumeration value="USPS"/>
      <xs:enumeration value="Overnight"/>
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="currRestrict">
    <xs:restriction base="xs:decimal">
    </xs:restriction>
</xs:simpleType>

</xs:schema>
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
user2789380
  • 33
  • 1
  • 1
  • 4
  • possible duplicate of [cvc-elt.1: Cannot find the declaration of element 'MyElement'](http://stackoverflow.com/questions/13310637/cvc-elt-1-cannot-find-the-declaration-of-element-myelement) – crownjewel82 Jun 19 '14 at 17:09

1 Answers1

3

Your instance document has xmlns="http://www.w3schools.com" but your schema has no targetNamespace. Therefore the schema gives a declaration of the element named Order in no namespace, but the validator is looking for a declaration of the element named Order in the http://www.w3schools.com namespace.

Add targetNamespace="http://www.w3schools.com" to the xs:schema opening tag and fix the xsi:schemaLocation to match - it is currently using the wrong namespace URI.

xsi:schemaLocation="http://www.w3schools.com order.xsd"

The namespace of the instance document, the targetNamespace of the schema, and the namespace that you are mapping to the schema with xsi:schemaLocation must all be the same.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • removing xmlns="http://www.w3schools.com" doesn't resolve the issue. Unless I misunderstood what you are saying. – user2789380 Sep 30 '13 at 21:25
  • Added the targetNamespace to the opening tag, still doesn't work. – user2789380 Sep 30 '13 at 21:29
  • @user2789380 I overlooked the schemaLocation mapping at first glance - that needs to be fixed as well. – Ian Roberts Sep 30 '13 at 21:35
  • Hi @IanRoberts, I have similar issue, however in my case I am marshalling JAXB objects to XML. Created a ticket with all the details. Please help if possible. https://stackoverflow.com/questions/72031169/unable-to-marshal-jaxb-object-due-to-saxparseexception-cannot-find-the-declarat – Rob Wilkinson Apr 27 '22 at 22:42