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

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 UTC