【问题标题】:Creating XML Schema创建 XML 模式
【发布时间】:2018-04-26 07:16:58
【问题描述】:

我有一个格式如下的 XML 文件:

<information xmlns:xlink="http://www.w3.org/1999/xlink">
  <fact>
    <header>some text</header>
    <text>some text</text>
  </fact>
<information>

我想知道是否有人可以帮助我创建一个 XML 模式文件?我目前有以下内容:

    <?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="information">
  <xs:complexType>
    <xs:sequence>
<xs:element name="fact">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="description" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
      </xs:sequence>
    </xs:complexType>
          </xs:element>

</xs:schema>

但是,当输入验证器时,会出现以下错误:

无效。 错误 - 第 12、9 行:org.xml.sax.SAXParseException;行号:12;列号:9; cvc-complex-type.2.4.d:发现以元素“事实”开头的无效内容。此时不需要子元素。

谢谢。

【问题讨论】:

    标签: xml xsd schema


    【解决方案1】:

    错误消息指向您输入的第 12 行。显示的示例输入只有 7 行,因此您必须验证不同的实例。

    我的猜测是,基于没有任何信息,fact 元素作为information 元素的子元素出现了不止一次。

    如果是这种情况,那么架构需要允许这样做:将 &lt;xs:element name="fact"&gt; 更改为 &lt;xs:element name="fact" maxOccurs="unbounded"&gt;

    【讨论】:

      猜你喜欢
      • 2014-11-21
      • 2010-11-02
      • 1970-01-01
      • 2011-02-05
      • 1970-01-01
      • 1970-01-01
      • 2019-12-01
      • 2015-04-12
      • 1970-01-01
      相关资源
      最近更新 更多