OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Conditional xml Schema

[ Lists Home | Date Index | Thread Index ]
  • To: xml-dev@lists.xml.org
  • Subject: Conditional xml Schema
  • From: "Jagdishwar B" <jagdishwar.beemanati@gmail.com>
  • Date: Sun, 11 Jun 2006 11:42:32 +0200
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=BKpkXaiHxVJRC/TJYtjI9dHRvDlr3tKS0g5l9+XBnUMRPMBd3aUWowsUq21CVN91g/ovwy0BuLlvwkEyJC8q4YQGvZUK/dUNorH6wo3qvmLCmutqcRd+6X5mcsRuppr0I04lhMO2oXUDeoRgwrumxcSfydBr2QdmeoW7qsZmiXc=

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




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS