W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2002

RE: XML Schema : Validating contents of one tag with another

From: Priscilla Walmsley <pwalmsley@vitria.com>
Date: Thu, 17 Jan 2002 10:03:29 -0800
Message-ID: <C72C18E3B1C0D411B7B600D0B7A9208C824AF6@vt-sjc-ms3.vitria.ad.vitriacorp.com>
To: kraj@infoprosolutions.com, xmlschema-dev@w3.org
Hi,

If you want the CARR_CODE to appear empty (as shown in your example), you
can't express this constraint in XML Schema.  But, you could simply omit the
CARR_CODE element entirely if a value is not present, and then you could
express it as follows:  

<xsd:complexType name="foo">
  <xsd:sequence>
    <xsd:element name="first"/>
    ....
    <xsd:sequence minOccurs="0">
      <xsd:element name="CARR_CODE"/>
      <xsd:element name="AIRBILL"/>
    </xsd:sequence>
    <xsd:element name="last"/>
  </xsd:sequence>
</xsd:complexType>

This would allow the AIRBILL element to appear only if there was a CARR_CODE
element.

Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley                          priscilla@walmsley.com
Vitria Technology                            http://www.vitria.com
Author, Definitive XML Schema                  (Prentice Hall PTR)
------------------------------------------------------------------

> -----Original Message-----
> From: xmlschema-dev-request@w3.org
> [mailto:xmlschema-dev-request@w3.org]On Behalf Of
> kraj@infoprosolutions.com
> Sent: Thursday, January 17, 2002 8:27 AM
> To: xmlschema-dev@w3.org
> Subject: XML Schema : Validating contents of one tag with another
> 
> 
> Hi,
> 
> How do I write a contraint in XML Schema document that 
> validates content
> of a tag based on content of another. e.g. below : The 
> AIRBILL can have
> a value only when CARR_CODE has a value otherwise not.
> Here e.g. 1 is valid but 2 is not.
> 1.
> <CARR_CODE>XYZ</CARR_CODE>
> <AIRBILL>123</AIRBILL>
> 
> 2.
> <CARR_CODE></CARR_CODE>
> <AIRBILL>12345</AIRBILL>
> 
> How do I constraint this dependency while writing the XML Schema
> document ?
> Can anybody help ?
> 
> Thanks,
> KRISHNA RAJ
> kraj@infoprosolutions.com
> 
> 
> 
> 
Received on Thursday, 17 January 2002 13:05:07 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:26 GMT