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

时间:2015-10-13 01:41:42

标签: xml xsd schema unique uniqueidentifier

我正在努力确保<context:property-placeholder location="config/application.properties"/> <import resource="jms-listener-container-config.xml"/> <!-- Get Input Messages --> <int-jms:message-driven-channel-adapter id="msgInCDC" channel="toRoute" container="messageListenerContainerCDC" error-channel="errorChannel" acknowledge="transacted"/> <int-jms:message-driven-channel-adapter id="msgInPDC" channel="toRoute" container="messageListenerContainerPDC" error-channel="errorChannel" acknowledge="transacted"/> <!-- Route Messages Depending on Root Element --> <int:channel id="toAircraftAssign"/> <int:channel id="toDiversionChange"/> <int:channel id="toFlightCreate"/> <int:channel id="toFlightPlanRelease"/> <int:channel id="toGateChange"/> <int:channel id="toPositionReport"/> <int:channel id="toScheduleChange"/> <int-xml:xpath-router id="flightUpdateRouter" input-channel="toRoute" default-output-channel="errorChannel" evaluate-as-string="true"> <int-xml:xpath-expression expression="name(/*)"/> <int-xml:mapping value="AircraftAssignment" channel="toAircraftAssign"/> <int-xml:mapping value="DiversionChangesUpdate" channel="toDiversionChange"/> <int-xml:mapping value="CreateFlight" channel="toFlightCreate"/> <int-xml:mapping value="FlightPlanRelease" channel="toFlightPlanRelease"/> <int-xml:mapping value="GateChange" channel="toGateChange"/> <int-xml:mapping value="PositionReportUpdate" channel="toPositionReport"/> <int-xml:mapping value="ScheduleChangesUpdate" channel="toScheduleChange"/> </int-xml:xpath-router> <int-jms:outbound-channel-adapter id="aircraftAssignMsgOut" channel="toAircraftAssign" connection-factory="remoteConnectionFactory" destination="aircraftAssignQueue"/> <int-jms:outbound-channel-adapter id="diversionChangeMsgOut" channel="toDiversionChange" connection-factory="remoteConnectionFactory" destination="diversionChangeQueue"/> <int-jms:outbound-channel-adapter id="flightCreateMsgOut" channel="toFlightCreate" connection-factory="remoteConnectionFactory" destination="flightCreateQueue"/> <int-jms:outbound-channel-adapter id="flightPlanReleaseMsgOut" channel="toFlightPlanRelease" connection-factory="remoteConnectionFactory" destination="flightPlanReleaseQueue"/> <int-jms:outbound-channel-adapter id="gateChangeMsgOut" channel="toGateChange" connection-factory="remoteConnectionFactory" destination="gateChangeQueue"/> <int-jms:outbound-channel-adapter id="positionReportMsgOut" channel="toPositionReport" connection-factory="remoteConnectionFactory" destination="positionReportQueue"/> <int-jms:outbound-channel-adapter id="scheduleChangeMsgOut" channel="toScheduleChange" connection-factory="remoteConnectionFactory" destination="scheduleChangeQueue"/> <!-- Error Handling --> <int-jms:outbound-channel-adapter id="errMsgOut" channel="errorChannel" connection-factory="remoteConnectionFactory" destination="failureQueue"/> <!-- Logger --> <int:wire-tap pattern="to*" order="7" channel="wireTapChannel"/> <int:logging-channel-adapter id="wireTapChannel" level="debug" logger-name="WIRETAP"/> <!-- Logger --> <!-- <int:wire-tap pattern="to*" order="0" channel="loggerChannel"/> --> <!-- <int:logging-channel-adapter id="loggerChannel" level="DEBUG" expression="'YYYY'"/> --> </beans>元素中的属性是唯一的。例如,属性<property_advert>应该是唯一的。我希望下面的XML由于重复的属性而失败。

agent_advert_reference

我的架构如下:

<?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>

我只使用了两天的XML架构,所以请耐心等待我的新问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

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

简而言之,您需要替换

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

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

我在本地检查过,这样做会在文档上返回一个身份约束错误。