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>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Dallan Baker
  • 125
  • 1
  • 3
  • 13

3 Answers3

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)

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
6

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

srjt
  • 316
  • 2
  • 10
  • My xml has xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance", but parser is still compaining about 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. – Angelina Nov 16 '18 at 14:18
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>
kjhughes
  • 106,133
  • 27
  • 181
  • 240