3
我目前正在學習XML,並已到達與多個名稱空間一起使用的XML模式的奇妙世界。XML模式中的childelements的名稱空間前綴
我的問題是當我應該也不必聲明一個名稱空間前綴。
考慮XML模式的以下片段:
<A:schema xmlns:A="http://www.w3.org/2001/XMLSchema"
targetNamespace="B"
xmlns:B="B"
elementFormDefault="qualified">
<A:element name="foo">
<complexType> <!-- or A:complexType?-->
<element name="bar" type="B:myType"/> <!-- or A:element?-->
</complexType>
</A:element>
<B:complexType name="myType">
<choice> <!--or B:choice?-->
<element name="baz" type="string"/> <!--or B:element?-->
<element name="bas" type="string"/> <!--or B:element?-->
</choice>
</B:complexType>
</A:schema>
我必須指定一個命名空間前綴的節點的所有子節點上的命名空間前綴,或者這是遺傳嗎?或者A:complexType
與complexType
不同時,它的父節點的A名稱空間前綴連接到它?
我想你已經誤解了命名空間是如何在這裏工作的。 '元素(在XMLSchema名稱空間中)是模式的一條指令,用於在模式的targetNamespace中聲明一個名爲'myType'的類型(即'urn:B') 。所以要說一個元素應該是'{urn:B} myType'類型的,你可以將一個前綴('B')映射到這個名稱空間URI,然後說''。 –