gpt4 book ai didi

xml - 根据所使用的 XML 解析器出现 XML 验证问题.....我如何表示要普遍接受的约束

转载 作者:数据小太阳 更新时间:2023-10-29 02:11:33 26 4
gpt4 key购买 nike

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

我有一个 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/canadianTVGAP}DemoValue',属性'marketRef':唯一标识约束'{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>

感谢您的帮助!

最佳答案

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

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

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

关于xml - 根据所使用的 XML 解析器出现 XML 验证问题.....我如何表示要普遍接受的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4648014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com