1
這裏是schema.xsd。 它定義了targetNamespace
ns
其中元素'A'
包括元素'B'
。如果元素未在全局級別定義,爲什麼targetNamespace被忽略?
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="ns">
<xsd:element name="root"/>
<xsd:element name="A">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="B" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
這裏是doc.xml。 它有一個包含'B'
節點的'A'
節點。 這個XML根據模式有效。
<root
xmlns="ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="ns schema.xsd" >
<A xmlns="ns">
<B xmlns=""/>
</A>
</root>
這聽起來一切OK ......除了'B'
是不是在命名空間ns
!
根據msdn,'B'
應位於命名空間ns
。
的targetNamespace是在此 架構命名空間的所有模式組件以及所包含使用任何模式的包括元素
問題出在哪裏:在我的理解還是在定義targetNamespace
? 。