<xsd:any/>
并不真正匹配“任何”元素 - 相反,它匹配范围内模式中某处声明的任何元素。
例如,以下模式定义了一个包含 xsd:any 的元素:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:any/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
然而,以下查询将失败:
import schema namespace my = "http://www.example.com/";
validate { <my:root><my:Child/></my:root> }
因为 my:Child 无处声明。
如果架构修改如下:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:any/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Child" type="xs:anyType"/>
</xs:schema>
那么查询应该成功。当然 xsd:any 匹配的元素可能在另一个命名空间中。