0

说明我的问题的最好方法是发布xsd我目前拥有的一些片段;它会让你更容易理解我的问题。

xsd这是我当前文件的一些片段:

<xs:element name="RiskAnalysis">
<xs:complexType>
  <xs:sequence>        
    <xs:element ref="RiskRating" maxOccurs="unbounded"/>
  </xs:sequence>
...
...
</xs:complexType>
</xs:element>

<xs:element name="RiskRating">
 <xs:complexType>
     ...
  <xs:attribute name="RatingType" use="required">
 <xs:simpleType>
      <xs:restriction base="xs:NMTOKEN">
        <xs:enumeration value="LocationNeighbourhood"/>
        <xs:enumeration value="Land"/>
        <xs:enumeration value="Improvements"/>
        <xs:enumeration value="Environmental"/>
        <xs:enumeration value="MarketSegment"/>
        <xs:enumeration value="ReducedValue"/>
        <xs:enumeration value="RecentMarket"/>           
        <xs:enumeration value="LocalEconomy"/>
        <xs:enumeration value="MarketVolatility"/>
        <xs:enumeration value="Other"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
...
 </xs:complexType>
</xs:element>

我遇到的问题是我需要限制我的方法,以便为is和的元素之间xsd创建一个 XOR ,但我想不出一种方法来做到这一点。RiskRatingsRatingTypeReducedValueRecentMarketValue

最好通过示例来描述,因此这里有一些示例RiskAnalysis元素(在xsd伪代码中)我可能会收到:

可接受的(即既不是也不是ReducedValue传入RecentMarket):

<RiskAnalysis>
     <RiskRating RatingType="Land" />
     <RiskRating RatingType="Other" />
</RiskAnalysis>

可接受(即仅ReducedValue传入):

<RiskAnalysis>
     <RiskRating RatingType="Land" />
     <RiskRating RatingType="Other" />
     <RiskRating RatingType="ReducedValue" />
</RiskAnalysis>

可接受(即仅RecentMarket传入):

<RiskAnalysis>
     <RiskRating RatingType="Land" />
     <RiskRating RatingType="Other" />
     <RiskRating RatingType="RecentMarket" />
</RiskAnalysis>

不接受并且应该抛出模式验证错误(即两者 RecentMarketReducedValue传入):

<RiskAnalysis>
     <RiskRating RatingType="Land" />
     <RiskRating RatingType="Other" />
     <RiskRating RatingType="RecentMarket" />
     <RiskRating RatingType="ReducedValue" />
</RiskAnalysis>

有人知道我会怎么做吗?

4

2 回答 2

1

XSD(单独)不可能!

解决方案:您许多人只需要使用主机代码来评估这部分。调用 XSD 验证(如 C#、CPP、JAVA 等)的主机程序能够验证这些条件。

于 2012-06-12T12:43:58.223 回答
0

The simplest way would be to eliminate the inconsistency in the analysis of your domain implicit in your schema: on the one hand, you want risk ratings of type RecentMarket and of type ReducedValue to be treated differently for purposes of validation, while on the other hand you are giving them the same element type, which says implicitly that for purposes validation they should be treated the same. The same? or different? Choose.

Given element types RecentMarketRating, ReducedValueRating, and OtherRiskRating, it's trivial to solve your problem. Given an XML encoding which calls them all the same thing, you main options are non-XSD code to do the validation, XSD 1.1 and the use of conditional type assignment or assertions, or Schematron in addition to your XSD 1.0.

于 2012-09-09T17:48:59.163 回答