Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

xml - Conditional Check based on another Tag

I have an xml which has a structure:

<?xml version="1.0" encoding="utf-8" ?>
<XYZInquiry>
    <Source>ABC</Source>
    <Info>19991234</Info> 
<RawData>
        <EmailAddress>[email protected]</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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...