Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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解析器……如何表示普遍接受的约束_Xml_Xsd_Xml Validation - Fatal编程技术网

XML验证问题取决于所使用的XML解析器……如何表示普遍接受的约束

XML验证问题取决于所使用的XML解析器……如何表示普遍接受的约束,xml,xsd,xml-validation,Xml,Xsd,Xml Validation,我有一个奇怪的情况,让我有点困惑 我有一个XML数据文件,我正试图根据一个模式对其进行验证,该模式似乎会根据所使用的解析器给出不同的结果。不知道我做错了什么,也不知道如何更好地表示模式中的约束,以便所有解析器都能正确地验证XML。。。。以下是架构问题部分的一个片段: <xsd:element name="DemoValues"> <xsd:annotation> <xsd:documentation>Demo values for any, or all,

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

我有一个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>

GAP上定义的任何或所有演示类别的演示值。A.
演示值包括对其应用的类别的引用,在适当的
格式和可选市场参考(如果是针对特定市场)。如果市场
参考值被省略。演示值适用于门店提供服务的整个区域。每个
演示类别在此演示值组中只能有一个演示值。然而如果
演示值是针对一个市场的,在这组数据中,每个市场可能有一个演示值
演示值。
对于演示类别,约束只允许最多一个演示值,并且每个
存在市场参考时的市场。

下面是有问题的XML:

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

0.40
15
产生以下错误:

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

简化错误为: 字段“marketRef”最多需要一个值

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

(一)


0.40
15
(二)


0.40
0.41
0.42
0.43
15
(三)


0.40
0.41
0.42
15

谢谢你的帮助

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

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


在定义
gap:demoValueType
时,只需使用
指定这两个属性即可。从您的示例来看,您可能希望在@demoref的定义上使用
use=“required”

我并不奇怪您从不同的处理器获得不同的结果,因为规范编写得非常模糊。但是,第二个xs:field中的union表达式显然是错误的——您不应该有一个可以选择多个节点的字段。如果您的第一个字段是@demoRef,第二个字段是@marketRef,我希望它能正常工作,但是,我一直在重新阅读规范,我会犹豫是否与解释不同的实现者争论。

我将不得不从供应商那里挖掘更多的原始文档……但我可以理解您的观点。。。。。我假设他们试图将“demoRef,marketRef”的唯一组合定义为列表中的唯一元素。。。。。不是一个专业的XSD开发人员…我假设有更好的方法来定义这种情况??在这种情况下定义模式时字段和属性之间有什么区别??(请原谅XSD新手)
 <DemoValues>
          <DemoValue demoRef="DM0" marketRef="MKT1">0.40</DemoValue>
          <DemoValue demoRef="DM1">15.00</DemoValue>
 </DemoValues>
<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>
<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>