【问题标题】:XSD file to validate XMLs用于验证 XML 的 XSD 文件
【发布时间】:2010-09-26 03:31:59
【问题描述】:

谁能帮我建立一个 XSD 文件来验证像这样的 XML:

[test]
[a/]
[b/]
[a/]
[b/]
[/test]

[test]
[a/]
[a/]
[b/]
[/test]

基本上,我可以拥有任意数量的<a> 和/或<b> 节点而无需任何其他规则(不能使用<xs:sequence>)。

【问题讨论】:

  • 你的语法很难理解。为什么不粘贴示例 XML?

标签: validation xsd


【解决方案1】:

如果您有很多 ab 节点,速度不会很快,但这与您所描述的相符。

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="test">
    <xs:complexType>
      <xs:sequence>
        <xs:choice maxOccurs="unbounded">
          <xs:element name="a"/>
          <xs:element name="b"/>
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

【讨论】:

    【解决方案2】:

    如果您粘贴示例 XML,我们可以为您提供更好的帮助。但是,Microsoft has an XSD code generator 根据您作为参数传入的 XML 文件生成 XSD。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      • 2012-07-23
      相关资源
      最近更新 更多