基于另一个标签的条件检查 [英] Conditional Check based on another Tag

查看:31
本文介绍了基于另一个标签的条件检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有结构的 xml:

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>

和相应的 XSD 验证为:

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>

我需要阅读信息标签,根据前 4 位数字,我需要在 RawData 标签上设置条件.即如果 Info 值以 1234 开头,则允许 RawData 标签,否则无效.请指教.

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.

推荐答案

你要的是 共现约束.这在 XSD 1.1(未广泛实现)和 Scehmatron 中是可能的.在 XSD 1.0 中不可能

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

这篇关于基于另一个标签的条件检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆