如何使用字段之间的关系创建XSD架构

时间:2013-02-08 05:39:47

标签: xml xsd schema keyref

我附加了xsd

的截断版本
<?xml version="1.0" encoding="UTF-8"?>

<xs:complexType name="School_ip_details">
    <xs:sequence>
        <xs:element type="xs:string" name="Tarun_Name" />
        <xs:element type="xs:string" name="Tarun_IP" />
        <xs:element type="xs:string" name="Tarun_Subnet" />

    </xs:sequence>
</xs:complexType>

<xs:element name="CLASSESS">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Taruns">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="Tarun" maxOccurs="127">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element type="xs:string" name="Tarun_Name" />
                                    <xs:element type="xs:string" name="Tarun_Prefix" />
                                    <xs:element type="xs:string" name="Tarun_Subnet" />
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>



            <xs:element name="Schools">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="School">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="School_IPdetails" type="School_ip_details" />
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>

                <xs:keyref name="TarunRef" refer="TarunKey">
                    <xs:selector xpath="." />
                    <xs:field xpath="./School/School_IPdetails/Tarun_Name" />

                </xs:keyref>
            </xs:element>

        </xs:sequence>
    </xs:complexType>
    <xs:key name="TarunKey">
        <xs:selector xpath="./Taruns/Tarun/Tarun_Name" />

        <xs:field xpath="." />
    </xs:key>

    <xs:key name="TarunIPKey">
        <xs:selector xpath="./Taruns/Tarun/Tarun_Prefix" />
        <xs:field xpath="." />
    </xs:key>

</xs:element>

这里我想实现以下场景。当我将CLASSES/Taruns/Tarun/Tarun_Name中的任何值引用至CLASSES/Scools/School/School_ip_details/Tarun_Name时,该特定CLASSES/Taruns/Tarun/Tarun_Prefix的{​​{1}}值应反映在Tarun_Name

请帮助我同样的

1 个答案:

答案 0 :(得分:0)

在XSD参考指南中查找身份限制(unique,key和keyref)。 (您没有XSD参考指南?获取一个。)