嘿,我正在尝试为不同的命名空间打开我的 XML 模式,这似乎有效,但现在所有默认命名空间元素都无效。
提前谢谢您。我试图实现与 Spring 中相同的模式扩展机制(即:spring-beans.2.5.xsd),它们也为 ##other
打开 bean
定义这有效!
我添加了 example of these three files轻松访问 zip 存档并将其上传到一键托管 Rapidshare。
我的错是什么?
示例列表.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>
自定义示例列表.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>
示例列表.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>
错误
发现以元素“bar”开头的无效内容。预期为“{foo, bar, baz, WC[##other:"http://www.example.org/schema/list"]}”之一
最佳答案
哇,这真是太难了。自从我不得不不断对 xsd 进行随机更改并验证以查看会发生什么以来,已经有很长一段时间了。 :)
添加elementFormDefault="qualified"
作为您的 <xs:schema>
的属性标签 example-list.xsd
这一切都得到了证实。我仍然有点困惑为什么需要这样做。
关于spring - 具有多个命名空间的 xml 扩展 xsd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2251668/