1

首先,我是 XSD/XML 的初学者。

总的来说,问题是我不太了解如何使用该xpath属性。

特别是,我无法将“keyref 元素”与对应的“关键元素”匹配。

XSD 架构

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:element name="NFFGs">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="NFFG" maxOccurs="unbounded" minOccurs="1"/>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:unique name="NFFGnameKey">
            <xsd:selector xpath="NFFG"/>
            <xsd:field xpath="@NFFGname"/>
        </xsd:unique>
    </xsd:element>

    <xsd:element name="NFFG">
        <xsd:complexType>
            <xsd:sequence>

                <xsd:element name="nodes" type="nodes_t" minOccurs="1" maxOccurs="1"/>

                <xsd:element name="links" type="links_t" minOccurs="1" maxOccurs="1"/>

                <xsd:element name="policies" type="policies_t" minOccurs="1" maxOccurs="1"/>

            </xsd:sequence>
            <xsd:attribute name="NFFGname" type="xsd:string" use="required"/>
        </xsd:complexType>
        <xsd:unique name="linkKey">
            <xsd:selector xpath="links/link"/>
            <xsd:field xpath="@linkID"/>
        </xsd:unique>
        <xsd:key name="node-key-id">
            <xsd:selector xpath="nodes/node"/>
            <xsd:field xpath="@nodeID"/>
        </xsd:key>
        <xsd:keyref name="dummySRC" refer="node-key-id">
            <xsd:selector xpath="links/link/SRC"/>
            <xsd:field xpath="@nodeID"/>
        </xsd:keyref>
        <xsd:keyref name="dummyDST" refer="node-key-id">
            <xsd:selector xpath="links/link/DST"/>
            <xsd:field xpath="@nodeID"/>
        </xsd:keyref>
        <xsd:keyref name="dummySRC1" refer="node-key-id">
            <xsd:selector xpath="policies/policy/reachability"/>
            <xsd:field xpath="@SRC"/>
        </xsd:keyref>
        <xsd:keyref name="dummyDST1" refer="node-key-id">
            <xsd:selector xpath="policies/policy/reachability"/>
            <xsd:field xpath="@DST"/>
        </xsd:keyref>
    </xsd:element>

    <xsd:complexType name="nodes_t">
        <xsd:sequence>
            <xsd:element name="node" type="node_t" minOccurs="1" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="node_t">
        <xsd:attribute name="nodeID" type="xsd:string" use="required"/>
        <xsd:attribute ref="functionalType"/>
    </xsd:complexType>

    <xsd:complexType name="links_t">
        <xsd:sequence>
            <xsd:element name="link" type="link_t" minOccurs="1" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="link_t">
        <xsd:sequence>
            <xsd:element name="SRC" type="nodeRef" minOccurs="1" maxOccurs="1"/>
            <xsd:element name="DST" type="nodeRef" minOccurs="1" maxOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute name="linkID" type="xsd:string" use="required"/>
    </xsd:complexType>

    <xsd:complexType name="nodeRef">
        <xsd:attribute name="nodeID"/>
    </xsd:complexType>

    <xsd:attribute name="functionalType">
        <xsd:simpleType>
            <xsd:restriction base="xsd:string">
                <xsd:enumeration value="firewall"/>
                <xsd:enumeration value="DPI"/>
                <xsd:enumeration value="NAT"/>
                <xsd:enumeration value="antispam"/>
                <xsd:enumeration value="web-cache"/>
                <xsd:enumeration value="VPN-gateway"/>
                <xsd:enumeration value="web-server"/>
                <xsd:enumeration value="web-client"/>
                <xsd:enumeration value="mail-server"/>
                <xsd:enumeration value="mail-client"/>
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:attribute>

    <xsd:complexType name="policies_t">
        <xsd:sequence>
            <xsd:element name="policy" type="policy_t" minOccurs="1" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="policy_t">
        <xsd:sequence>
            <xsd:element name="reachability" type="reachability_t"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="reachability_t">
        <xsd:sequence>
            <xsd:element name="reachability_verified" type="xsd:boolean"/>
            <xsd:element name="trasversal" type="trasversal_t" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute name="SRC" use="required"/>
        <xsd:attribute name="DST" use="required"/>
    </xsd:complexType>

    <xsd:complexType name="trasversal_t">
        <xsd:sequence>
            <xsd:element name="trasversal" type="xsd:boolean" fixed="true"/>
        </xsd:sequence>
    </xsd:complexType>

</xsd:schema>

XML 示例

<?xml version="1.0"?>
<NFFGs
        xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
        xsd:noNamespaceSchemaLocation="nffgInfo.xsd"
>

    <NFFG NFFGname="nffg-1">
        <nodes>
            <node nodeID="n1" functionalType="web-client"/>
            <node nodeID="n2" functionalType="firewall"/>
            <node nodeID="n3" functionalType="NAT"/>
            <node nodeID="n4" functionalType="web-server"/>
            <node nodeID="n5" functionalType="web-server"/>
        </nodes>
        <links>
            <link linkID="l1">
                <SRC nodeID="n1" />
                <DST nodeID="n5"/>
            </link>
            <link linkID="l2">
                <SRC nodeID="n4" />
                <DST nodeID="n5"/>
            </link>
        </links>
        <policies>
            <policy>
                <reachability SRC="n7" DST="n2">
                    <reachability_verified>false</reachability_verified>
                </reachability>
            </policy>
        </policies>
    </NFFG>

</NFFGs>

我给出的错误是:

在此处输入图像描述

欢迎任何形式的建议和/或建议,即使是在问题主题之外。

4

0 回答 0