<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> }
,因爲我:孩子無處聲明。
如果模式修改如下:
<?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匹配的元素可能位於另一個名稱空間中。
在你的情況下,將在架構中聲明「book」和「title」元素(作爲xs:schema根元素的直接子元素)的幫助嗎? –
另外,您可以通過將屬性processContents =「skip」添加到xsd:any標籤來繞過該問題。這不需要聲明與xsd:any匹配的元素。 –