xsd - xml with same element with different value need a schema -
for following xml need schema.
<?xml version="1.0" encoding="utf-8"?> <overall_operation> <operation type="list_products"> <ops_description>listing products of company</ops_description> <module>powesystem</module> <comp_name>apc</comp_name> <prod_price>50k$</prod_price> <manf_date>2001</manf_date> <pool_name>electrical</pool_name> <fail_retry>2</fail_retry> <storage_type>avialble</storage_type> <storage_check>false</storage_check> <api_type>sync</api_type> <product_name>transformer</product_name> </operation> <operation type="search_product"> <ops_description>search products of company repository</ops_description> <module>high-voltage</module> <module>powesystem</module> <comp_name>apc</comp_name> <pool_name>electrical</pool_name> <fail_retry>2</fail_retry> <storage_type>avialble</storage_type> <storage_check>false</storage_check> <api_type>sync</api_type> <product_name>setup-transformer</product_name> </operation> </overall_operation>
here different elements operation list_products
,search_products
, on. each element have common attributes such ops_description
,module
, on.
also of unique attributes each element such prod_price
,manf_date
etc.
i want have xml schema validate. of attributes optional.
i tried using abstract , derived not make work.
what want achieve not possible xml schema. definition states every element or attribute must validated on own , without reference other elements or attributes.
the best solution can group
optional dependent elements:
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:element name="overall_operation"> <xs:complextype> <xs:sequence> <xs:element name="operation" minoccurs="0" maxoccurs="unbounded"> <xs:complextype> <xs:sequence> <xs:element name="ops_description" /> <xs:element name="module" minoccurs="1" maxoccurs="2" /> <xs:element name="comp_name" /> <xs:group ref="price_and_date" minoccurs="0" maxoccurs="1" /> <xs:element name="pool_name" /> <xs:element name="fail_retry" /> <xs:element name="storage_type" /> <xs:element name="storage_check" /> <xs:element name="api_type" /> <xs:element name="product_name" /> </xs:sequence> <xs:attribute name="type" type="xs:string" /> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> <xs:group name="price_and_date"> <xs:sequence> <xs:element name="prod_price" /> <xs:element name="manf_date" /> </xs:sequence> </xs:group> </xs:schema>
use minoccurs
, maxoccurs
attributes control optional elements , groups.
Comments
Post a Comment