Reputation: 340
I am getting error validating with this XML:
<xs:simpleType name="XYZ">
<xs:restriction base="xs:nonNegativeInteger">
<xs:enumeration value="1">
</xs:enumeration>
<xs:enumeration value="2">
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
XML value :
<XYZ>2</XYZ>
cvc-enumeration-valid: Value '2' is not facet-valid with respect to enumeration '[1]'. It must be a value from the enumeration.
Can anyone please help me to understand the problem? How to resolve it ?
Upvotes: 4
Views: 34840
Reputation: 2923
I've got this working, I think it addresses your question, but as KJ indicates without an example we're really just guessing.
Here's a sample XML
<xml>
<XYZ>3</XYZ>
</xml>
And a sample schema
<xs:schema
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="xml">
<xs:complexType>
<xs:sequence>
<xs:element name='XYZ'>
<xs:simpleType>
<xs:restriction base="xs:nonNegativeInteger">
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
With a value of 3 (invalid), I get the following exception.
The 'XYZ' element is invalid - The value '3' is invalid according to its datatyp
e 'NonNegativeInteger' - The Enumeration constraint failed. Line: 2 Column: 10
Upvotes: 1
Reputation: 111611
The error message,
cvc-enumeration-valid: Value '2' is not facet-valid with respect to enumeration '[1]'. It must be a value from the enumeration.
and the simpleType
from your question do not agree.
The error message implies that only 1
is allowed yet 2
was encountered; your type definition does indeed allow both 1
and 2
.
To elicit an actual error message pertaining to your xs:simpleType
, your XML would have to use a value, say 3
, not allowed. Then, you would receive an error message like this:
cvc-enumeration-valid: Value '3' is not facet-valid with respect to enumeration '[1, 2]'. It must be a value from the enumeration.
Therefore, your (first, maybe only?) mistake is in believing that the posted xs:simpleType
definition has anything to do with that error message.
Upvotes: 4