0

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>

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I should have copied and pasted my code, the missing " on lines 8 and 9 were just typos. I still have the error.
1

You are missing "

Lines 8 and 9 should be

<xs:attribute name="key" type="xs:string"/>
<xs:attribute name="value" type="xs:string"/>

1 Comment

Sorry, I should have copied and pasted my code, the missing " on lines 8 and 9 were just typos. I still have the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.