Wednesday, 15 May 2013

xsd - xml schema restriction list with different sub elements by value -



xsd - xml schema restriction list with different sub elements by value -

i create element has different subelements depending on value of 1 of these elements. wonder if , how can accomplish (best possible solution). if type piece there must weight element. if type kilogram or gram or ... not need it.

<?xml version="1.0" encoding="utf-8"?> <amounts> <amount> <type>piece</type> <value>6</value> <weight> <value>1.5</value> <type>liter</type> </weight> </amount> <amount> <type>kilogram</type> <value>0.610</value> </amount> </amounts>

so thought might this, errors (see below).

<?xml version="1.0" encoding="utf-8"?> <schema xmlns="http://www.w3.org/2001/xmlschema" targetnamespace="http://www.test.org/amount" xmlns:amount="http://www.test.org/amount" elementformdefault='qualified'> <element name="amount"> <complextype> <choice> <group ref="amount:kilogram" /> <group ref="amount:piece" /> </choice> </complextype> </element> <group name="kilogram"> <sequence> <element name="type" fixed="kilogram" /> <element name="value" type="float" /> </sequence> </group> <group name="piece"> <sequence> <element name="type" fixed="piece" /> <element name="value" type="int" /> <element name="weight"> <complextype> <sequence> <element name="type" type="amount:amounttype" /> <element name="value" type="float" /> </sequence> </complextype> </element> </sequence> </group> <simpletype name="amounttype"> <restriction base="string"> <enumeration value="kg" /> <enumeration value="g" /> <enumeration value="mg" /> <enumeration value="lb" /> </restriction> </simpletype> </schema>

error @ line 5 is:

multiple annotations found @ line: - cos-nonambig: "http://www.test.org/amount":type , "http://www.test.org/amount":type (or elements substitution group) violate "unique particle attribution". during validation against schema, ambiguity created 2 particles. - cos-element-consistent: error type '#anontype_amount'. multiple elements name 'value', different types, appear in model group.

if made "type" attribute rather element, in xsd 1.1 using conditional type assignment. otherwise, sorry, you're out of luck.

xml xsd

No comments:

Post a Comment