【发布时间】:2011-07-13 10:39:10
【问题描述】:
我正在努力开发一个允许来自混合命名空间的属性的架构。
这里是 xxx_schema2.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="qualified"
targetNamespace="http://www.mrbouffant.com/schema2"
xmlns:xxx="http://www.mrbouffant.com/schema2">
<xs:attributeGroup name="schema2AttributeGroup">
<xs:attribute name="schema2Attribute1 " type="xs:string"/>
<xs:attribute name="schema2Attribute2 " type="xs:string"/>
</xs:attributeGroup>
</xs:schema>
这里是导入 xxx_schema2 的 xxx_schema1.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
xmlns:xxx="http://www.mrbouffant.com/schema2">
<xs:import namespace="http://www.mrbouffant.com/schema2" schemaLocation="xxx_schema2.xsd"/>
<!-- ROOT ELEMENT -->
<xs:element name="rootElement" type="rootElementType" />
<!-- COMPLEX TYPES -->
<xs:complexType name="rootElementType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="xxx:schema2AttributeGroup"/>
<xs:attribute name="schema1Attribute1" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
这是我想根据 xxx_schema1.xsd 验证的 XML 文档:
<?xml version="1.0" encoding="UTF-8"?>
<rootElement xmlns:xxx='http://www.mrbouffant.com/schema2/'
schema1Attribute1="foo"
xxx:schema2Attribute1="bar"
xxx:schema2Attribute2="far" />
当 Saxon-EE 解析器尝试根据模式验证 XML 文档时,它生成的错误实际上是:
Engine name: Saxon-EE 9.3.0.5
Severity: error
Description: Attribute @xxx:schema2Attribute1 is not allowed on element <rootElement>
(it would be allowed in namespace http://www.mrbouffant.com/schema2)
与
Engine name: Saxon-EE 9.3.0.5
Severity: error
Description: Attribute @xxx:schema2Attribute2 is not allowed on element <rootElement>
(it would be allowed in namespace http://www.mrbouffant.com/schema2)
请您帮助我了解我在架构定义或 XML 文档中做错了什么,导致验证无法成功?谢谢。
【问题讨论】:
-
是的,这是可能的。不清楚你在问什么。你试过了吗?如果它不起作用,发生了什么?
-
我被告知“元素
上不允许使用属性 @xxx:schema2Attribute1(在名称空间 中将允许)”就我所问的而言.. 我想知道通常如何构建 schema2、schema1 和 XML 文档,以便正确验证。谢谢! -
如果您向我们展示您正在谈论的实际架构片段以及完整的错误,而不是用英文描述它们,将会有所帮助。
-
我已经用两个模式文档和一个 XML 文档更新了原始问题。解析器提供的错误也包括在内。谢谢。
标签: xml xsd xml-namespaces