FF FF
FF FF

Reputation: 31

XSD validation - The "xs" for element "xs:schema" is not bound error

I'm a beginner. Here is my XML Schema code :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.w3.org/1999/xhtml">
    <xs:element name="breaksfast_menu">

        <xs:complexType>
            <xs:sequence>
                <xs:element name="food">
                    <xs:complexType>
                        <xs:sequence>
                         <xs:element name="name" type="xs:string"/>
                         <xs:element name="price" type="xs:string"/>
                         <xs:element name="description" type="xs:string"/>
                         <xs:element name="calories" type="xs:string"/>

                        </xs:sequence>
                    </xs:complexType>
                </xs:element>

            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

The XML document:

    <?xml version="1.0" encoding="UTF-8"?>
    <breakfast_menu xmlns:xsi="http://www.w3.org/1999/xhtml">

        <food>
            <name>Belgian Waffles</name>
            <price>$5.95</price>
            <description>
                Two of our famous Belgian Waffles with plenty of real maple syrup
            </description>
            <calories>650</calories>
        </food>

  </breakfast_menu>

Upon trying to validate the XML file, I get an error that says:

The prefix xs for element xs:schema is not bound.

Upvotes: 3

Views: 5626

Answers (1)

kjhughes
kjhughes

Reputation: 111491

Correction of initial error

The prefix xs for element xs:schema is not bound.

In any XML document that uses namespaces, including an XSD, all used namespace prefixes (e.g. xs) must be bound to a namespace URI (e.g. http://www.w3.org/2001/XMLSchema) in order for the XML document to be namespace-well-formed.

Furthermore, XSD elements are defined in a particular namespace: http://www.w3.org/2001/XMLSchema (not http://www.w3.org/1999/xhtml, which is the namespace for XHTML, not XSD).

Therefore, change

xmlns="http://www.w3.org/1999/xhtml"

to

xmlns:xs="http://www.w3.org/2001/XMLSchema"

to eliminate your initial error.

Correction of aditional errors

After making the above fix, a couple additional issues remain to resolve.

In your XSD

  1. breaksfast_menu should be breakfast_menu to match your XML;
  2. xmlns:xsi="http://www.w3.org/1999/xhtml" is unnecessary, but should you need it to define, say, xsi:noNamespaceSchemaLocation, you'll need to correct it to be xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance".

After making all of the above changes, your XML will be valid against your XSD.


Since you're still having some trouble, here are the corrected XML and XSD. Hope this helps:

XML

<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:noNamespaceSchemaLocation="try.xsd">
  <food>
    <name>Belgian Waffles</name>
    <price>$5.95</price>
    <description>
      Two of our famous Belgian Waffles with plenty of real maple syrup
    </description>
    <calories>650</calories>
  </food>
</breakfast_menu>

XSD

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="breakfast_menu">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="food">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="name" type="xs:string"/>
              <xs:element name="price" type="xs:string"/>
              <xs:element name="description" type="xs:string"/>
              <xs:element name="calories" type="xs:string"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Upvotes: 3

Related Questions