Question

I have an xml which has a structure:

<?xml version="1.0" encoding="utf-8" ?>
<XYZInquiry>
    <Source>ABC</Source>
    <Info>19991234</Info> 
<RawData>
        <EmailAddress>abc@email.com</EmailAddress>
</RawData>
</XYZInquiry>

and corresponding XSD for validation as:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema id="XYZInquiry" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="XYZInquiry">
        <xsd:complexType>
            <xsd:all>
                <xsd:element name="Source" minOccurs="1" maxOccurs="1" type="xsd:string" />
                <xsd:element name="Info" minOccurs="1" maxOccurs="1" type="xsd:string" />
<xsd:element name="RawData" minOccurs="0" maxOccurs="1">
<xsd:complexType>
                        <xsd:sequence>
                        <xsd:element name="EmailAddress" minOccurs="0" maxOccurs="1"/>
</xsd:element>
                    </xsd:sequence>
                </xsd:complexType>

I need to read Info Tag and based on the first 4 digits, I need to put condition on the RawData Tag. i.e. if The Info value starts with 1234, then RawData Tag is allowed else Invalid. Kindly advise.

Was it helpful?

Solution

What you are asking for is co-occurrence constraints. This is possible in XSD 1.1 (not widely implemented) and Scehmatron. It is not possible in Not possible in XSD 1.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top