XSD validation Error

  • Thread starter Thread starter deepak
  • Start date Start date
D

deepak

Hi There,

For an element i have XSD defined as show below


<xs:element name="Foo" type="FooType" minOccurs="0" />


<xs:simpleType name="FooType">
<xs:restriction base="xs:string">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
</xs:restriction>


and in my XML if i have <Foo/> then the validation will fail stating
"Enumertion contraint failed"
but my understanding is this should not happen since i have defined
minOccurs="0" in my XSD.


any comments/suggestions apprectiated

Thanks
Deepak
 
<xs:element type="MyType" />

<xs:simpleType name="FooType">
<xs:restriction base="xs:string">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
</xs:restriction>
</xs:simpleType>

<xs:complexType name="MyType">
<xs:sequence>
<xs:element name="Foo" type="FooType" minOccurs="0" />
<xs:sequence>
</xs:complexType>

defines a document whose root element is called MyType, and who contains a
sequence of elements. The sequence of elements contained within the MyType
element
can be ZERO OR MORE Foo elements whose type is FooType. The element type
FooType has a restriction imposed which is ... the content is of base-type
string (though in this example maybe it should be an integer), AND it is ONE
OF THE ENUMERATED VALUES.

That means that the following Xml fragments are valid according to this XSD

<MyType />

<MyType>
<Foo>1</Foo>
</MyType>

<MyType>
<Foo>1</Foo>
<Foo>3</Foo>
</MyType>

Therefore when you attempt to validate any of the following Xml fragments
using the above XSD, it will fail.

<MyType>
<Foo />
</MyType>

<MyType>
<Foo>4</Foo>
</MyType>

<MyType>
<Foo>1</Foo>
<Foo>4</Foo>
</MyType>

I hope that makes sense :o)
 
Back
Top