Conditional Check based on another Tag

谁说胖子不能爱 提交于 2019-12-13 08:28:39

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/19923116/conditional-check-based-on-another-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!