i have xml writing validator tool our clients can test sample feeds i'm pretty new xsd. point validates correctly based on cookie cutter example wanted throw other scenarios @ it. first 1 came having different orders of elements in base node.
example: using following complextype validate each transaction node
<xs:complextype name="transactiontype"> <xs:sequence> <xs:element type="xs:string" name="id"/> <xs:element type="xs:string" name="type"/> <xs:element type="xs:float" name="amount"/> <xs:element type="xs:string" name="description"/> <xs:element type="xs:string" name="status"/> <xs:choice> <xs:element name="transacted_on" type="xs:date"/> <xs:element name="transacted_at" type="xs:date"/> </xs:choice> <xs:choice> <xs:element name="posted_on" type="xs:date"/> <xs:element name="posted_at" type="xs:date"/> </xs:choice> </xs:sequence> </xs:complextype> the following example node in correct sequence order , validates correctly
<transaction> <id>20150617-123456</id> <type>debit</type> <amount>17.44</amount> <description>debit card: cafe 06/16/15</description> <status>posted</status> <transacted_on>2015-06-17</transacted_on> <posted_on>2015-06-16</posted_on> </transaction> but want able have elements in order. following validate correctly. idea elements present , can in order.
<transactions> <transaction> <amount>17.44</amount> <id>20150617-123456</id> <type>debit</type> <description>debit card: cafe 06/16/15</description> <status>posted</status> <transacted_on>2015-06-17</transacted_on> <posted_on>2015-06-16</posted_on> </transaction> <transaction> <id>20150617-123456</id> <type>credit</type> <amount>17.44</amount> <description>visa card: payment</description> <status>posted</status> <transacted_on>2015-06-17</transacted_on> <posted_on>2015-06-16</posted_on> </transaction> </transactions> i did research , pointed towards using xs:all element should want. changed schema use xs:all instead of xs:sequence.
<xs:complextype name="transactiontype"> <xs:all> <xs:element type="xs:string" name="id"/> <xs:element type="xs:string" name="type"/> <xs:element type="xs:float" name="amount"/> <xs:element type="xs:string" name="description"/> <xs:element type="xs:string" name="status"/> <xs:choice> <xs:element name="transacted_on" type="xs:date"/> <xs:element name="transacted_at" type="xs:date"/> </xs:choice> <xs:choice> <xs:element name="posted_on" type="xs:date"/> <xs:element name="posted_at" type="xs:date"/> </xs:choice> </xs:all> </xs:complextype> when run validation after making change still error:
this element not expected. expected ( id ).
what missing here?
xml schema not allow xs:choice child of xs:all.
workarounds:
- add wrapper element around
xs:choiceelements. - abandon
xs:all, live fixed ordering viaxs:sequence.
i'd suggest in practice xs:sequence works fine , avoids problem others arise xs:all, including violations of unique particle principle.
Comments
Post a Comment