[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Conditional xml Schema
Hi all, Is it possible to define the xml schema (xsd) conditionally based on certain values. For e.g. My xml document is: <myRoot> <fruit myAttr="Apple"> <elementApple1>elemAppleOne</elementApple1> </fruit> <fruit myAttr="Mango"> <elementMango1>elemMangoOne</elementMango1> </fruit> </myRoot> the xsd file should define the structure (i mean put the constraints) in such a way that: if the <fruit> element has myAttr="Apple", then it should force to have <elementApple1> child element, and if the <fruit> element has myAttr="Mango", then it should force to have <elementMango1> child element I created following schema, <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="fruit"> <xs:complexType> <xs:choice> <xs:element name="elementApple1" type="xs:string"/> <xs:element name="elementMango1" type="xs:string"/> </xs:choice> <xs:attribute name="myAttr" type="xs:string" use="required"></xs:attribute> </xs:complexType> </xs:element> <xs:element name="myRoot"> <xs:complexType> <xs:sequence> <xs:element ref="fruit" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> but the above schema is allowing '<fruit myAttr="Apple">' to contain '<elementMango1>' child element. basically i would like to have different structure for the <fruit> elements depending upon the vaule present in myAttr attribute. Thanks in advance. Jagdishwar B
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|