2010-02-12 74 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