java - xml element validation against xsd - how to define unordered element? -
now i'm validating xml
this:
<?xml version="1.0" encoding="utf-8"?> <all> <allelem> <a>12345</a> <b>2</b> <c>3</c> <d> <d1>4</d1> <d2>5</d2> <d3>6</d3> </d> <d> <d1>7</d1> <d2>8</d2> <d3>9</d3> </d> </allelem> </all>
i wrote simple xsd
this:
<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:element name="all"> <xs:complextype> <xs:sequence> <xs:element name="allelem" maxoccurs="1"> <xs:complextype> <xs:sequence> <xs:element name="a" type="xs:string"/> <xs:element name="b" type="xs:string"/> <xs:element name="c" type="xs:string"/> <xs:element name="d" minoccurs="1" maxoccurs="unbounded"> <xs:complextype> <xs:sequence> <xs:element name="d1" type="xs:string"/> <xs:element name="d2" type="xs:string"/> <xs:element name="d3" type="xs:string"/> </xs:sequence> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:schema>
my question is: i'm using xs:sequence
, don't want xml element ordered, can't use xs:all, because allow element occurs once max, xml element "d" should able appear more once. there solution in xsd can define unordered element appears once or appears many times? in other words, want know there such xsd tag can define unordered elements can appear more once.
in xsd 1.0:
you can use xs:all in place of xs:sequence, each element can appear (0 or 1) times.
you can use xs:choice minoccurs=0 maxoccurs=unbounded, each element can appear number of times
in xsd 1.1:
- you can use xs:all , specify min/max cardinality each element (which asking for)
xsd 1.1 available in xerces (beta version) , saxon (current release saxon-ee 9.5).
Comments
Post a Comment