xml - How to force child element to have a value in XSD? -
i have xml (as example) segment called type
within segment order
. segment 1 many, have :
<order> <type>1</type> <type>2</type> <type>3</type> </order>
now validation should be, there should segment type
value 1 in segment order
, if not, validation error should occur. tried validations, not correct result. has thought on how implement , if possible?
xsd 1.0
your constraint cannot expressed in xsd 1.0.
xsd 1.1
your constraint can expressed in xsd 1.1 using assertion state there @ least 1 type
child of order
has value of 1
:
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:vc="http://www.w3.org/2007/xmlschema-versioning" vc:minversion="1.1"> <xs:element name="order"> <xs:complextype> <xs:sequence> <xs:element name="type" maxoccurs="unbounded" type="xs:integer"/> </xs:sequence> <xs:assert test="type = 1"/> </xs:complextype> </xs:element> </xs:schema>
Comments
Post a Comment