问题
I get an error on validation:
Error - Line 14, 36: org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 36; s4s-elt-must-match.1: The content of 'simpleType' must match (annotation?, (restriction | list | union)). A problem was found starting at: attribute.
How to resolve it?
My XML fragment
<CHANEL_NAME lang="RUS/MD">N4</CHANEL_NAME>
And XSD:
<xs:element name="CHANEL_NAME">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="40"/>
</xs:restriction>
<xs:attribute name="lang">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="MD"/>
<xs:enumeration value="RUS"/>
<xs:enumeration value="RUS/MD"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:simpleType>
</xs:element>
So I need in attribute 'lang' only determined values like 'MD', 'RUS' or 'RUS/MD'. I read examples and I guess it's OK.
Or is enumeration only for elements and not for attributes?
回答1:
The problem is the first simpleType. Simple types can't have attribute.
You probably need a complex type with simple content. Something like:
<xs:element name="CHANEL_NAME">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:string">
<xs:length value="40"/>
<xs:attribute name="lang">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="MD"/>
<xs:enumeration value="RUS"/>
<xs:enumeration value="RUS/MD"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
(Not tested.)
Also consider naming your anonymous types.
ps. Also consider using/restricting xs:language as language type.
Всего наилучшего.
来源:https://stackoverflow.com/questions/26991135/xml-schema-validator-error-on-attribute-declaration