4

我有一个奇怪的情况,让我有点困惑......

我有一个 XML 数据文件,我试图针对一个模式进行验证,该模式似乎会根据所使用的解析器给出不同的结果。不知道我做错了什么或如何更好地表示模式中的约束,以便所有解析器都可以正确验证 XML ......这是模式问题部分的片段:

<xsd:element name="DemoValues">
<xsd:annotation>
  <xsd:documentation>Demo values for any, or all, of the demo categories defined on the GAP . A
    demo value includes a reference to the category it applies to, a value in the appropriate
    format and an optional market reference if it is for a specific market. If the market
    reference is omitted the demo value applies to the entire area serviced by the outlet. Each
    demo category may only have a single demo value within this group of demo values. However if
    the demo value is for a market, there may be a demo value per market within this group of
    demo values. </xsd:documentation>
</xsd:annotation>
<xsd:complexType>
  <xsd:sequence>
    <xsd:element name="DemoValue" type="gap:demoValueType" maxOccurs="unbounded"/>
  </xsd:sequence>
</xsd:complexType>
<xsd:unique name="DemoValueConstraint">
  <xsd:annotation>
    <xsd:documentation>Constraint allows only up to one demo value for a demo category, and per
      market when a market reference exists. </xsd:documentation>
  </xsd:annotation>
  <xsd:selector xpath="gap:DemoValue"/>
  <xsd:field xpath="@demoRef"/>
  <xsd:field xpath="@marketRef|@demoRef"/>
</xsd:unique>

这是有问题的 XML:

<DemoValues>
          <DemoValue demoRef="DM0" marketRef="MKT1">0.40</DemoValue>
          <DemoValue demoRef="DM1">15.00</DemoValue>
</DemoValues>

产生此错误:

元素“{http://www.AAAA.org/schemas/canadianTVAP}DemoValue”,属性“marketRef”:唯一标识约束字段的 XPath '@marketRef|@demoRef''{http://www. AAAA.org/schemas/canadianTVGAP}DemoValueConstraint' 评估为具有多个成员的节点集。

简化错误是:字段“marketRef”最多期望一个值。

xml 的目的是允许所有这些组合:

1)

 <DemoValues>
          <DemoValue demoRef="DM0" marketRef="MKT1">0.40</DemoValue>
          <DemoValue demoRef="DM1">15.00</DemoValue>
 </DemoValues>

2)

<DemoValues>
          <DemoValue demoRef="DM0" marketRef="MKT1">0.40</DemoValue>
          <DemoValue demoRef="DM0" marketRef="MKT2">0.41</DemoValue>
          <DemoValue demoRef="DM0" marketRef="MKT3">0.42</DemoValue>
          <DemoValue demoRef="DM0" marketRef="MKT4">0.43</DemoValue>
          <DemoValue demoRef="DM1">15.00</DemoValue>
</DemoValues>

3)

<DemoValues>
          <DemoValue demoRef="DM0" marketRef="MKT1">0.40</DemoValue>
          <DemoValue demoRef="DM1" marketRef="MKT1">0.41</DemoValue>
          <DemoValue demoRef="DM2" marketRef="MKT1">0.42</DemoValue>
          <DemoValue demoRef="DM3">15.00</DemoValue>
</DemoValues>

谢谢你的帮助!!

4

2 回答 2

1

除了将属性列表限制为您描述的组合之外,您是否需要在此处使用字段?

一个 XML 元素最多可以有一个任何命名属性的实例。这是关于 XML 的事实,与模式无关。

在您的定义中gap:demoValueType,只需使用 指定两个属性<xsd:attribute ... />。从你的例子看,你可能想use="required"在@demoref的定义上使用)

于 2011-01-10T15:08:43.647 回答
1

我对您在这里从不同的处理器获得不同的结果并不感到惊讶,因为规范的编写非常晦涩。但是,您的第二个 xs:field 中的联合表达式显然是错误的 - 您永远不应该有一个可以选择多个节点的字段。如果您的第一个字段是@demoRef 并且您的第二个字段是@marketRef,我希望它能够正常工作,但是,我一直在重新阅读规范,我会犹豫与解释它不同的实现者争论。

于 2011-01-10T16:19:36.510 回答