0

我对 XML Schema 有一些问题。我需要在我的 XML 文件中添加一些 HTML 代码,我发现 xs:any 会有所帮助。但是 xmllint 会返回如下错误:

example.xml:4: element h1: Schemas validity error : Element 'h1': This element is not expected. Expected is ( {http://www.w3.org/1999/xhtml}* ).

XML:

<?xml version="1.0" encoding="UTF-8"?>
<foo>
<bar>
    <h1>Lorem ipsum</h1>
</bar>
</foo>

架构:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="foo">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="bar" minOccurs="1" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:any namespace="http://www.w3.org/1999/xhtml" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

我做错了什么?

4

1 回答 1

3

该模式表示每个bar元素都可以包含一个位于http://www.w3.org/1999/xhtml名称空间中的元素,但是在实例文档中,您使用了一个名为的元素h1,该元素不在名称空间中。您需要放在xmlns="http://www.w3.org/1999/xhtml",h1或在树的更上方放置一个前缀声明(例如<foo xmlns:h="http://www.w3.org/1999/xhtml">),然后在 XHTML 元素上使用该前缀(<h:h1>)。

于 2014-02-17T09:39:59.307 回答