Error: The prefix "xsi" for attribute "xsi:schemaLocation" is not bound
Asked Answered
F

3

7

I am having trouble validating my XML against an XSD. The validator throws

The prefix "xsi" for attribute "xsi:schemaLocation" associated with an element type "mpreader" is not bound.

Here's the an XML clip

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<mpreader xmlns="C:\Users\Dallan\Desktop\Mpreader\" xmlns:xs="http://www.w3.org/20one/XMLSchema-instance" 
 xsi:schemaLocation="C:\Users\Dallan\Desktop\Mpreader\mpreaderschemafinal.xsd"> 
                <firmware>"3.4.16"</firmware>  

                <hardware>"2.3.53"</hardware>  

                <sn>"234-1three5"</sn>

                <devices> 
            </devices>
        </mpreader>

And here's the XSD clip

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="C:Users/Dallan/Desktop/Mpreader/" elementFormDefault="qualified" targetNamespace="C:\Users\Dallan\Desktop\Mpreader\">

<xs:element name="mpreader">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
    <xs:element name="firmware" type="xs:string"/>
    <xs:element name="hardware" type="xs:string"/>
    <xs:element name="sn" type="xs:string"/>
    <xs:element name="devices">
        <xs:complexType>
        <xs:sequence maxOccurs="unbounded">
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Fumarole answered 3/8, 2015 at 23:38 Comment(0)
U
9

"The prefix "xsi" for attribute "xsi:schemaLocation" associated with an element type "mpreader" is not bound."

Then bind it, dear Dallan, dear Dallan, dear Dallan...

Just add a namespace declaration binding the prefix xsi to the namespace http://www.w3.org/2001/XMLSchema-instance

(https://en.wikipedia.org/wiki/There%27s_a_Hole_in_My_Bucket)

Unblushing answered 4/8, 2015 at 7:26 Comment(1)
haha yeah I realized I made a stupid mistake and had xs instead of xsiFumarole
O
6

Your XML should declare the namespace for xsi e.g. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Opacity answered 3/8, 2015 at 23:44 Comment(1)
My xml has xmlns:xsi="w3.org/2001/XMLSchema-instance", but parser is still compaining about <PropertyType xsi:nil="true" /> javax.xml.bind.UnmarshalException\n - with linked exception:\n[org.xml.sax.SAXParseException; lineNumber: 15; columnNumber: 256; The prefix \"xsi\" for attribute \"xsi:nil\" associated with an element type \"PropertyType\" is not bound.Sekofski
N
5

Quick answer: Fix the way you use xsi:schemaLocation:

<mpreader xmlns="C:\Users\Dallan\Desktop\Mpreader\"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="C:\Users\Dallan\Desktop\Mpreader\
                              C:\Users\Dallan\Desktop\Mpreader\mpreaderschemafinal.xsd">

Details

  • Declare an xsi (not xs) namespace prefix to match its use in xsi:schemaLocation.
  • Declare the proper namespace for xsi: http://www.w3.org/2001/XMLSchema-instance, not http://www.w3.org/20one/XMLSchema-instance.
  • Change the value of xsi:schemaLocation to be a namespace-location pair.
  • Remove the whitespace in devices (although that may just be an artifact of pruning).

There is also a missing closing xs:sequence tag in your XSD (but, again, that may just be a pruning mistake):

Altogether then, the following XSD,

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified"
           targetNamespace="C:\Users\Dallan\Desktop\Mpreader\">

  <xs:element name="mpreader">
    <xs:complexType>
      <xs:sequence maxOccurs="unbounded">
        <xs:element name="firmware" type="xs:string"/>
        <xs:element name="hardware" type="xs:string"/>
        <xs:element name="sn" type="xs:string"/>
        <xs:element name="devices">
          <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

will validate the following XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<mpreader xmlns="C:\Users\Dallan\Desktop\Mpreader\"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="C:\Users\Dallan\Desktop\Mpreader\
                              C:\Users\Dallan\Desktop\Mpreader\mpreaderschemafinal.xsd">
  <firmware>"3.4.16"</firmware>  
  <hardware>"2.3.53"</hardware>  
  <sn>"234-1three5"</sn>
  <devices/> 
</mpreader>
Northeast answered 4/8, 2015 at 2:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.