正确使用XML Schema的说明/示例?

时间:2015-09-12 23:31:32

标签: xml xsd xml-validation

我对XML Schema感到困惑。我相信它们用于定义要用作模板的自定义元素。

说我有以下架构:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <!-- definition of simple elements -->
  <xs:element name="text" type="xs:string"/>

  <!-- definition of attributes -->
  <xs:attribute name="choice_value" type="xs:int"/>

  <!-- definition of complex elements -->
  <xs:element name="choice">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="text" minOccurs="1"/>
        </xs:sequence>
        <xs:attribute ref="choice_value" use="required"/>
    </xs:complexType>
  </xs:element>

</xs:schema>

有人可以提供一个详细的例子,一个关于我如何使用和导入这个模式的完整的单元素XML文件吗?我可以导入或包含它,当我尝试声明我的元素时,它说并且无法找到。 Google搜索结果只展示了如何导入,但实际上并没有应用它。

0 个答案:

没有答案