Question

I am confused as to why my XML schema will not pass Java's xml schema validation. I got my java validation code from link to the code. It should be standard stuff. I am told that a problem was found starting at: attribute. It is at lineNumber: 8; columnNumber: 48.

My xml is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

 <xs:element name ="Entries">
  <xs:complexType>
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="entry">
        <xs:attribute name="key" type="xs:string"/>
        <xs:attribute name="value" type="xs:string"/>
      </xs:element>
    </xs:sequence>
   </xs:complexType>
  </xs:element>

</xs:schema>
Was it helpful?

Solution

Lines 8 and 9 are both missing a closing quote on the type attribute. This fixed XML passes validation for me:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

 <xs:element name ="Entries">
  <xs:complexType>
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="entry">
        <xs:attribute name="key" type="xs:string"/>
        <xs:attribute name="value" type="xs:string"/>
      </xs:element>
    </xs:sequence>
   </xs:complexType>
  </xs:element>

</xs:schema>

EDIT 1

Ok, upon further examination it turns out the xml is just malformed. The <xs:attribute> tag can not be a child of the <xs:element> tag. If you're trying to define two attributes on the "entry" element, your schema definition needs to look like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="Entries">
    <xs:complexType>
      <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:element name="entry">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute name="key" type="xs:string"/>
                <xs:attribute name="value" type="xs:string"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

OTHER TIPS

You are missing "

Lines 8 and 9 should be

<xs:attribute name="key" type="xs:string"/>
<xs:attribute name="value" type="xs:string"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top