Reputation: 127
My requirement is I have three elements where ProductID
and DivisionID
is required and Unit is optional.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element name="Product">
<xs:complexType>
<xs:sequence>
<xs:element name="productID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Unit" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DivisionID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<Message>
<Product>
<productID>ABC-EDI</productID>
</Product>
</Message>
Cvc-complex-type.2.4.b: The Content Of Element 'Product' Is Not Complete. One Of '{Unit, DivisionID}' Is Expected., Line '4', Column '14'.
Error should be that only DivisionID
is expected. Why Unit
is expected?
Upvotes: 2
Views: 4002
Reputation: 111521
Your XML is valid against your XSD as posted.
If you were to omit the required DivisionID
element, you would indeed receive an validation error along the lines of
cvc-complex-type.2.4.b: The content of element 'Product' is not complete. One of '{Unit, DivisionID}' is expected.
This error should be read as saying not that Unit
is required after productID
but rather that Unit
or DivisionID
is expected to follow productID
. You're understandably looking to be told the minimum change necessary to meet the XSD's requirements. However, it's making a broader statement along the lines of
Hey, I just saw a close tag for
Product
, and its content model remains unsatisfied. BeforeProduct
ends, I expected to see one ofUnit
orDivisionID
at this point.
Upvotes: 3