2010-02-12 72 views
3

嘿,即時通訊嘗試打開我的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

回答

3

哇,這是一個艱難的。這是很長一段時間,因爲我不得不對xsd進行隨機更改並驗證以查看會發生什麼。 :)

elementFormDefault="qualified"添加爲<xs:schema>標記的屬性example-list.xsd並且全部驗證。我仍然有點困惑,爲什麼這是必要的。

+0

非常瘋狂,非常感謝!如果你發現,爲什麼這是必要的,請給我發一個note =) – codevour 2010-02-22 08:05:22

+0

當example-list.xsd中的'elementFormDefault =「unqualified」(這是默認值)時,它表示本地元素(未直接定義元素在模式下)不應該在實例XML中被限定,即他們不應該定義他們的名字空間。但是在你的exmaple-list.xml中,本地元素欄通過在其父(action-list)上定義一個默認名稱空間來定義它的名稱空間爲「http:// www.example.org/schema/list」。 – sengs 2012-07-12 08:23:14

+0

要測試這個,你可以在example-list.xml的bar元素中添加'xmlns =「」'。這會使該元素屬於空名稱空間,並且應驗證XML。 – sengs 2012-07-12 08:24:02

0

看起來問題出在你的定製例如,list.xsd。您將元素「eek」定義爲不在名稱空間中。

在該模式中將xmlns:balvi="http://www.example.org/schema/custom"更改爲xmlns="http://www.example.org/schema/custom"

編輯:好吧,所以如果你修好了,這裏變得棘手。我唯一能想到的是,因爲你指定了##other,所以只有之外的一個元素你的目標命名空間必須出現在那裏。但是,您可以選擇來自目標命名空間的元素。在規範中我看不到任何可以消除這種情況的東西。

也許你可能想改變這個選擇到一個簡單的序列,看看它是否工作。如果是這樣,你知道什麼是錯的。如果它仍然中斷,則可能是您的模式包含失敗。

+0

好的,謝謝 - 我糾正了這個(更新的問題),但不幸的是,這並沒有幫助我的問題。 – codevour 2010-02-12 20:50:03

+0

它仍然與「序列」而不是「選擇」打破,我不明白它爲什麼會打破。我使用與春季相同的方式使用模式包含機制。 – codevour 2010-02-15 11:00:16