首页 > 解决方案 > 创建 XML 模式

问题描述

我有一个格式如下的 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:发现以元素“事实”开头的无效内容。此时不需要子元素。

谢谢你。

标签: xmlxsdschema

解决方案


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

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

如果是这种情况,那么架构需要允许这样做:更改<xs:element name="fact"><xs:element name="fact" maxOccurs="unbounded">


推荐阅读