Reputation: 10323
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>
Upvotes: 0
Views: 1097
Reputation: 113
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>
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>
Upvotes: 1
Reputation: 404
You are missing "
Lines 8 and 9 should be
<xs:attribute name="key" type="xs:string"/>
<xs:attribute name="value" type="xs:string"/>
Upvotes: 1