Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
确保XML架构中的属性值唯一_Xml_Xsd_Schema_Unique_Uniqueidentifier - Fatal编程技术网

确保XML架构中的属性值唯一

确保XML架构中的属性值唯一,xml,xsd,schema,unique,uniqueidentifier,Xml,Xsd,Schema,Unique,Uniqueidentifier,我试图确保元素中的属性是唯一的。例如,属性agent\u advert\u reference应该是唯一的。我希望下面的XML由于重复属性而失败 <?xml version="1.0" encoding="UTF-8"?> <property_adverts xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://www.example.org/XmplifyDerivedSc

我试图确保
元素中的属性是唯一的。例如,属性
agent\u advert\u reference
应该是唯一的。我希望下面的XML由于重复属性而失败

<?xml version="1.0" encoding="UTF-8"?>
<property_adverts xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://www.example.org/XmplifyDerivedSchema.xsd">
    <header>
        <harvest_run_info>
            <harvest_time>12:05:00</harvest_time>
            <harvest_date>2015-10-10</harvest_date>
            <harvester_version>1.0</harvester_version>
            <harvester_path>/Users/xandrani/Sites/property_harvester_new</harvester_path>
        </harvest_run_info>
        <property_agent>
            <company_name>CPS Homes</company_name>
        </property_agent>
    </header>
    <adverts>
        <property_advert agent_advert_reference="X1204" static_advert_url="https://www.example.com/properties/1204" original_html_file="/RandomName/advert_30Sep2015_14436555622486.html">
            <rent_cost>450</rent_cost>
            <rent_frequency>per month</rent_frequency>
            <number_of_bedrooms>4</number_of_bedrooms>
            <available_date>now</available_date>
            <property_description></property_description>
            <main_photo_url>https://www.example.com/properties/X1204/fred.jpg</main_photo_url>
            <branch_name>Brusque Bay</branch_name>
            <property_type>House</property_type>
            <building_name/>
            <street_name>High Street</street_name>
            <postcode>CF11 6BP</postcode>
            <furnished>true</furnished>
            <location_area>Canton</location_area>
        </property_advert>
        <property_advert agent_advert_reference="X1204" static_advert_url="https://www.example.com/properties/1204" original_html_file="/RandomName/advert_30Sep2015_14436555622486.html">
            <rent_cost>450</rent_cost>
            <rent_frequency>per month</rent_frequency>
            <number_of_bedrooms>4</number_of_bedrooms>
            <available_date>now</available_date>
            <property_description></property_description>
            <main_photo_url>https://www.example.com/properties/X1204/fred.jpg</main_photo_url>
            <branch_name>Brusque Bay</branch_name>
            <property_type>House</property_type>
            <building_name/>
            <street_name>High Street</street_name>
            <postcode>CF11 6BP</postcode>
            <furnished>true</furnished>
            <location_area>Canton</location_area>
        </property_advert>
    </adverts>
</property_adverts>

12:05:00
2015-10-10
1
/用户/xandrani/Sites/property_harvester_new
CPS之家
450
每月
4.
现在
https://www.example.com/properties/X1204/fred.jpg
布鲁克湾
房子
商业街
CF11 6BP
真的
广州
450
每月
4.
现在
https://www.example.com/properties/X1204/fred.jpg
布鲁克湾
房子
商业街
CF11 6BP
真的
广州
我的模式如下:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:annotation>
        <xs:documentation xml:lang="en">
            XML Schema.
        </xs:documentation>
    </xs:annotation>
    <xs:element name="harvest_run_info" type="harvest_run_info_type"/>
    <xs:complexType name="harvest_run_info_type">
        <xs:all minOccurs="1" maxOccurs="1">
            <xs:element name="harvest_time" type="xs:time" minOccurs="1" maxOccurs="1"/>
            <xs:element name="harvest_date" type="xs:date" minOccurs="1" maxOccurs="1"/>
            <xs:element name="harvester_version" type="harvester_version_type" minOccurs="1" maxOccurs="1"/>
            <xs:element name="harvester_path" type="xs:string" minOccurs="1" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>
    <xs:element name="property_advert" type="property_advert_type"/>    
    <xs:complexType name="property_advert_type">
        <xs:all>
            <xs:element name="rent_cost" type="xs:positiveInteger" minOccurs="1" maxOccurs="1"/>
            <xs:element name="rent_frequency" type="rent_frequency_type" minOccurs="1" maxOccurs="1"/>
            <xs:element name="number_of_bedrooms" type="xs:positiveInteger" minOccurs="1" maxOccurs="1"/>
            <xs:element name="available_date" type="available_date_type" minOccurs="1" maxOccurs="1"/>
            <xs:element name="property_description" type="xs:string" minOccurs="1" maxOccurs="1"/>
            <xs:element name="main_photo_url" type="xs:anyURI" minOccurs="0" maxOccurs="1"/>
            <xs:element name="branch_name" type="xs:string" minOccurs="1" maxOccurs="1"/>
            <xs:element name="property_type" type="property_type_type" minOccurs="1" maxOccurs="1"/>
            <xs:element name="building_name" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="street_name" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="postcode" type="ukPostCode" minOccurs="0" maxOccurs="1"/>
            <xs:element name="furnished" type="xs:boolean" minOccurs="1" maxOccurs="1"/>
            <xs:element name="location_area" type="xs:string" minOccurs="0" maxOccurs="1"/>
        </xs:all>
        <xs:attribute name="agent_advert_reference" type="xs:string"/>
        <xs:attribute name="original_html_file" type="xs:string" use="required"/>
        <xs:attribute name="static_advert_url" type="xs:string"/>
    </xs:complexType>
    <xs:element name="rent_frequency" type="rent_frequency_type"/>
    <xs:simpleType name="rent_frequency_type">
        <xs:restriction base="xs:string">
            <xs:enumeration value="per month"/>
            <xs:enumeration value="per week"/>
            <xs:enumeration value="Per Month"/>
            <xs:enumeration value="Per Week"/>
            <xs:enumeration value="Per month"/>
            <xs:enumeration value="Per week"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="property_type" type="property_type_type"/>
    <xs:simpleType name="property_type_type">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Room"/>
            <xs:enumeration value="House"/>
            <xs:enumeration value="Flat"/>
            <xs:enumeration value="room"/>
            <xs:enumeration value="house"/>
            <xs:enumeration value="flat"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="property_agent" type="property_agent_type"/>
    <xs:complexType name="property_agent_type">
        <xs:all>
            <xs:element name="company_name" type="xs:string" minOccurs="1" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>
    <xs:simpleType name="available_date_type">
        <xs:union>
            <xs:simpleType>
                <xs:restriction base="xs:date"/>
            </xs:simpleType>
            <xs:simpleType>
                <xs:restriction base="xs:NMTOKEN">
                    <xs:enumeration value="Now"/>
                    <xs:enumeration value="now"/>
                    <xs:enumeration value="NOW"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:union>
    </xs:simpleType>
    <xs:simpleType name="harvester_version_type">
        <xs:restriction base="xs:token">
            <xs:pattern value="([0-9]+\.)?([0-9]+\.)?([0-9]+)"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="ukPostCode">
        <xs:restriction base="xs:token">
            <xs:pattern value="(GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKPSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) [0-9][A-Z-[CIKMOV]]{2})"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="header" type="header_type"/>
    <xs:complexType name="header_type">
        <xs:sequence>
            <xs:element name="harvest_run_info" type="harvest_run_info_type" minOccurs="1" maxOccurs="1"/>
            <xs:element name="property_agent" type="property_agent_type" minOccurs="1" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>


    <xs:element name="property_adverts" type="property_adverts_type"/>
    <xs:complexType name="property_adverts_type">
        <xs:sequence>
            <xs:element name="header" type="header_type" minOccurs="1" maxOccurs="1"/>
            <xs:element name="adverts" minOccurs="1" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="adverts" type="adverts_type">
        <xs:unique name="unique_original_html_file">
            <xs:selector xpath="property_advert"/>
            <xs:field xpath="@original_html_file"/>
        </xs:unique>
        <xs:unique name="unique_agent_advert_reference">
            <xs:selector xpath="property_advert"/>
            <xs:field xpath="@agent_advert_reference"/>
        </xs:unique>
        <xs:unique name="unique_static_advert_url">
            <xs:selector xpath="property_advert"/>
            <xs:field xpath="@static_advert_url"/>
        </xs:unique>
    </xs:element>
    <xs:complexType name="adverts_type">
        <xs:sequence>
            <xs:element name="property_advert" type="property_advert_type" minOccurs="1" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>   
</xs:schema>

XML模式。

我使用XML模式才两天,所以请耐心回答我的新问题。提前感谢。

模式中的唯一约束根本不被考虑,因为在复杂类型属性_adverts_type中,您使用隐含的复杂类型xs:anyType重新定义了名为adverts的元素(因此,它几乎可以接受adverts元素下的任何内容)。相反,您应该使用ref属性参考广告的全局元素声明

简言之,您需要替换

<xs:element name="adverts" minOccurs="1" maxOccurs="1"/>



我在本地检查过这样做是否会在文档上返回标识约束错误。

根本不考虑模式中的唯一约束,因为在复杂类型属性_adverts_type中,您使用隐含的复杂类型xs:anyType重新定义了名为adverts的元素(因此,它几乎可以接受广告元素下的任何内容)。相反,您应该使用ref属性参考广告的全局元素声明

简言之,您需要替换

<xs:element name="adverts" minOccurs="1" maxOccurs="1"/>



我已经在本地检查过,这样做会在您的文档上返回标识约束错误。

很抱歉在这里添加了这么多代码。我看到了很多关于唯一性的代码片段,但当我将它们插入XML架构时,这些片段都不起作用。因此我需要一个适用于所有代码的答案……也许我添加了snip宠物在错误的地方,因此必须在我所有代码的上下文中查看任何答案。放置所有代码实际上非常好,因为它允许任何人复制您的错误并进行调查。如果没有完整的代码,我可能无法抓住问题。为在此处放置这么多代码表示歉意。我已经看到了很多代码段谈到了唯一性,但当我将它们插入XML模式时,这些代码段都不起作用。因此,我需要一个适用于所有代码的答案…也许我将代码段添加到了错误的位置,因此有必要在所有代码的上下文中查看任何答案。放置所有代码实际上非常好,因为它允许任何Body复制您的错误并进行调查。如果没有完整的代码,我可能无法发现问题。此外,您似乎在许多其他地方使用了属性名而不是ref,因此您的所有全局元素声明(属性_除外)此外,您似乎在许多其他地方使用了属性名而不是ref,因此您的所有全局元素声明(属性_adverts one除外)也将被忽略。