嘿,即時通訊嘗試打開我的XML架構爲不同的命名空間,這似乎工作,但所有默認的命名空間元素現在是無效的。擴展xsd的XML與多個命名空間
預先感謝您。我試圖實現與Spring(i.E .: spring-beans.2.5.xsd)中完成的相同的模式擴展機制,它們也打開bean
定義,也適用於##other
,此工作正常!
我添加了一個example of these three files,可以方便地訪問一個zip存檔並將其上傳到一鍵式主機快速分享。
什麼是我的錯?
例如-list.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.example.org/schema/list"
xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/schema/list">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" />
<xs:complexType name="ExampleListModelType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="ExampleListGroup" />
</xs:choice>
</xs:complexType>
<xs:group name="ExampleListGroup">
<xs:choice>
<xs:element name="foo" type="xs:string" />
<xs:element name="bar" type="xs:string" />
<xs:element name="baz" type="xs:string" />
<xs:any namespace="##other" processContents="strict" />
</xs:choice>
</xs:group>
<xs:element name="action-list" type="ExampleListModelType" />
</xs:schema>
定製示例-list.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.org/schema/custom" elementFormDefault="qualified"
targetNamespace="http://www.example.org/schema/custom">
<xs:element name="eek" type="xs:string" />
</xs:schema>
例如-list.xml
<?xml version="1.0" encoding="UTF-8"?>
<action-list xmlns="http://www.example.org/schema/list"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:custom="http://www.example.org/schema/custom"
xsi:schemaLocation="
http://www.example.org/schema/list example-list.xsd
http://www.example.org/schema/custom custom-example-list.xsd">
<custom:eek></custom:eek>
<bar></bar>
</action-list>
錯誤
Invalid content was found starting with element 'bar'. One of '{foo, bar, baz, WC[##other:"http://www.example.org/schema/list"]}' is expected
非常瘋狂,非常感謝!如果你發現,爲什麼這是必要的,請給我發一個note =) – codevour 2010-02-22 08:05:22
當example-list.xsd中的'elementFormDefault =「unqualified」(這是默認值)時,它表示本地元素(未直接定義元素在模式下)不應該在實例XML中被限定,即他們不應該定義他們的名字空間。但是在你的exmaple-list.xml中,本地元素欄通過在其父(action-list)上定義一個默認名稱空間來定義它的名稱空間爲「http:// www.example.org/schema/list」。 – sengs 2012-07-12 08:23:14
要測試這個,你可以在example-list.xml的bar元素中添加'xmlns =「」'。這會使該元素屬於空名稱空間,並且應驗證XML。 – sengs 2012-07-12 08:24:02