【问题标题】:Validating schema using attribute使用属性验证架构
【发布时间】:2012-08-03 08:01:03
【问题描述】:

我有以下 xml:

<Root>
    <SomethingA/>
    <SomethingB/>
    <SomethingC/>
    <SomeOtherThing action="Foo">
        <Bar/>
        <Bar/>
    </SomeOtherThing>
    <SomeOtherThing action="Poo">
        <BarFoo/>
        <BarNoo/>
    </SomeOtherThing>
</Root>

我想创建一个模式,它将验证如果元素是 SomeOtherThing,那么如果动作是 Foo,则子元素只能是 Bar;如果动作是便便,那么子元素可以是 BarFoo(和/或)BarNoo。

关于如何完成它的任何想法(仅使用 xsd)?

此外,该解决方案需要在 C# 上运行。

【问题讨论】:

标签: c# xml validation xsd schema


【解决方案1】:

这种条件验证不能在 XSD 1.0 中完成。它可以在 XSD 1.1 中使用称为“条件类型分配”的特性来完成。

【讨论】:

  • 有没有办法在 Visual Studio 中使用 XSD 1.1? (2010/2012)我在任何地方都看到没有支持它(编辑问题)
  • XSD 1.1 目前在 Saxon (9.4) 和 Apache Xerces (beta) 中受支持。我知道其他未宣布的处理器正在开发中(但不是来自微软)。微软似乎不再有兴趣让他们的 XML 产品与 W3C 标准保持同步。
猜你喜欢
  • 2016-03-21
  • 2011-12-17
  • 1970-01-01
  • 2011-06-18
  • 2016-02-11
  • 1970-01-01
  • 2021-06-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多