gpt4 book ai didi

xsd : element with unique value(Xsd:具有唯一值的元素)

转载 作者:bug小助手 更新时间:2023-10-28 09:48:50 26 4
gpt4 key购买 nike



I'm working on xml and xsd, and i have several different elements in my xsd, and among all element i would like that some of them are unique.

我正在处理XML和xsd,我的xsd中有几个不同的元素,在所有元素中,我希望其中一些是唯一的。


here an example of my xml file:

下面是我的XML文件的一个示例:


<?xml version="1.0" encoding="UTF-8"?>
<LIST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<PRODUCT>
<TYPE>SecurityGateway</TYPE>
<PRIMARY_IP>192.168.0.23</PRIMARY_IP>
<PRIMARY_SUBNET_MASK>255.255.0.0</PRIMARY_SUBNET_MASK>
<PRIMARY_PORT>443</PRIMARY_PORT>
<SECONDARY_IP>192.168.0.66</SECONDARY_IP>
<SECONDARY_SUBNET_MASK>255.255.128.0</SECONDARY_SUBNET_MASK>
<SECONDARY_PORT>443</SECONDARY_PORT>
</PRODUCT>
<PRODUCT>
<TYPE>SecurityGateway</TYPE>
<PRIMARY_IP>192.168.0.66</PRIMARY_IP>
<PRIMARY_SUBNET_MASK>255.255.0.0</PRIMARY_SUBNET_MASK>
<PRIMARY_PORT>443</PRIMARY_PORT>
</PRODUCT>
<PRODUCT>
<TYPE>SecurityGateway</TYPE>
<PRIMARY_HOST_NAME>xx.yy.zz</PRIMARY_HOST_NAME>
<PRIMARY_PORT>443</PRIMARY_PORT>
</PRODUCT>
</LIST>

I would like to have an xsd which detect if an IP address is present more than once doesn't matter if it is in the PRIMARY_IP or SECONDARY_IP.
As you can see, in my xml, the product 1 as its PRIMARY_IP equal to the SECONDARY_IP of the product 2 -> I want to refuse this kind of xml because it is not possible that two product share the same IP.

我希望有一个xsd,它检测一个IP地址是否多次出现,无论它是在PRIMARY_IP中还是在SUBCENT_IP中。正如您所看到的,在我的XML中,产品1作为其主IP等于产品2的辅助IP->我想拒绝这种XML,因为两个产品不可能共享相同的IP。


Here an extract of my xsd :

下面是我的xsd的摘录:


<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="_IPv4Address">
<xs:restriction base="xs:string">
<xs:pattern value="(([1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.){3}([1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="_Hostname">
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="255" />
<xs:pattern value="([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="LIST">
<xs:complexType>
<xs:sequence>
<!-- details of each product element -->
<xs:element name="PRODUCT" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="TYPE" type="xs:string" minOccurs="1" maxOccurs="1">
</xs:element>
<!-- Either product is accessible by static IP or by hostname -->
<xs:choice minOccurs="1" maxOccurs="1">
<xs:sequence>
<xs:element name="PRIMARY_IP" type="_IPv4Address">
</xs:element>
<xs:element name="PRIMARY_SUBNET_MASK" type="_IPv4Address">
</xs:element>
<xs:element name="PRIMARY_PORT" type="xs:unsignedShort" minOccurs="1" maxOccurs="1">
</xs:element>
</xs:sequence>
<xs:sequence>
<xs:element name="PRIMARY_HOST_NAME" type="_Hostname">
</xs:element>
<xs:element name="PRIMARY_PORT" type="xs:unsignedShort" minOccurs="1" maxOccurs="1">
</xs:element>
</xs:sequence>
</xs:choice>

<!-- Product can also have a secondary IP or hostname -->
<xs:choice minOccurs="0" maxOccurs="1">
<xs:sequence>
<xs:element name="SECONDARY_IP" type="_IPv4Address">
</xs:element>
<xs:element name="SECONDARY_SUBNET_MASK" type="_IPv4Address">
</xs:element>
<xs:element name="SECONDARY_PORT" type="xs:unsignedShort">
</xs:element>
</xs:sequence>
<xs:sequence>
<xs:element name="SECONDARY_HOST_NAME" type="_Hostname">
</xs:element>
<xs:element name="SECONDARY_PORT" type="xs:unsignedShort">
</xs:element>
</xs:sequence>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Thank you for your help.

谢谢你的帮助。


I try to add this in my xsd, but it doesn't work because it only compare the value for the "same" element:

我尝试将其添加到我的xsd中,但它不起作用,因为它只比较“相同”元素的值:


<xs:unique name="uniquePRIMARY_IP">
<xs:selector xpath="PRODUCT"/>
<xs:field xpath="PRIMARY_IP"/>
</xs:unique>
<xs:unique name="uniquePRIMARY_Hostname">
<xs:selector xpath="PRODUCT"/>
<xs:field xpath="PRIMARY_HOST_NAME"/>
</xs:unique>
<xs:unique name="uniqueSECONDARY_IP">
<xs:selector xpath="PRODUCT"/>
<xs:field xpath="SECONDARY_IP"/>
</xs:unique>
<xs:unique name="uniqueSECONDARY_HOSTNAME">
<xs:selector xpath="PRODUCT"/>
<xs:field xpath="SECONDARY_HOST_NAME"/>
</xs:unique>

更多回答
优秀答案推荐

Try a uniqueness constraint (at the level of the LIST element) with <selector path="PRODUCT/PRIMARY_IP | PRODUCT/SECONDARY_IP"/> and <field path="."/>

尝试使用<选择器路径=“PRODUCT/PRIMARY_IP|PRODUCT/辅助性IP”/>和 进行唯一性约束(在列表元素级别)。


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com