模式中的参考标准HTML元素

时间:2013-02-27 17:40:21

标签: xml xsd

我有一个HTML类型的自定义xml架构。我想引用一些可以在这个html类型(a,p,ul等)中使用的“标准”html元素。 我找到了以下具有这些元素的模式。

http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd

我添加了以下行来导入架构

<xs:import schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd" />

我正在尝试使用内部元素,如下所示

<xs:complexType name="Html">
  <xs:choice maxOccurs="unbounded">
    <xs:element ref="ul"></xs:element>
  </xs:choice>
</xs:complexType>

它不起作用,我错过了什么?这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:2)

导入的模式中定义的HTML元素位于xhtml命名空间中:http://www.w3.org/1999/xhtml。因此,您应该在namespace="http://www.w3.org/1999/xhtml"元素中添加<xs:import>属性。为了引用导入模式中定义的元素和类型,您需要具有一个名称空间定义,其中包含xhtml名称空间的一些前缀。也就是说:您需要在xmlns:xh="http://www.w3.org/1999/xhtml"元素中使用<xs:schema>定义,然后在引用XHTML中定义的类型,元素等时使用此前缀(此处为xh)架构。

因此,您的示例代码变为:

<xs:schema 
    ... 
    xmlns:xh="http://www.w3.org/1999/xhtml"
    ...
    >

<xs:import schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd"
           namespace="http://www.w3.org/1999/xhtml" />

    <xs:complexType name="Html">
      <xs:choice maxOccurs="unbounded">
        <xs:element ref="xh:ul"></xs:element>
      </xs:choice>
    </xs:complexType>

</xs:schema>
相关问题