【发布时间】:2014-10-17 13:24:23
【问题描述】:
我想在命名空间“foo”中定义一个模式,该模式在命名空间“bar”中导入一个定义了复杂类型的模式,并引用“bar”中的类型。我缺少什么来验证这个? MWE 下面。
根架构:
<?xml version="1.0" encoding="ISO-8859-1"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:f="foo" xmlns:b="bar" targetNamespace="foo">
<import schemaLocation="Import.xsd" namespace="bar"/>
<element name="root" type="f:Root"/>
<complexType name="Root">
<sequence>
<!--<element ref="b:imported"/>-->
<element name="imported" type="b:ImportedType"/>
</sequence>
</complexType>
</schema>
导入的架构:
<?xml version="1.0" encoding="ISO-8859-1"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="bar"
elementFormDefault="qualified">
<complexType name="ImportedType"/>
<!--
<element name="imported">
<complexType/>
</element>
-->
</schema>
XML 实例:
<?xml version="1.0" encoding="UTF-8"?>
<f:root xmlns:f="foo" xmlns:b="bar">
<b:imported/>
</f:root>
结果: 元素“{bar}imported”:不需要此元素。预期为 ({foo}imported )。
如果我将设计模式从 Venetian Blind 更改为 Salami Slice(在模式中切换 cmets),一切正常。但是我们所有的其他模式都在 VB 中,所以我不希望针对这种情况进行更改。
尝试使用 xmllint 和 notepad++ 进行验证
【问题讨论】:
-
所以你的目标是拥有
b:imported而不是f:imported? -
目标是让 XML 文档保持原样。我不能改变它的布局。我也无法更改导入模式的布局,因为它不是我们的。我试图理解为什么它认为“imported”应该属于命名空间 foo,而我已经将它的类型指定为“b:ImportedType”(bar)
-
你有点误会了。 type 仍在
b中,但您的元素imported未导入,它在您的架构中声明。 -
是的,我刚刚意识到这一点,因为我已经发布了您评论的答案。因此,要在不同的命名空间中使用子元素,我是否必须
才能“突破”当前命名空间? -
我一直这么认为,但我还在架构规范中看到了
targetNamespace属性:w3.org/TR/xmlschema11-1/#dcl.elt.local 所以我会尝试写targetNamespace="bar",或者可能是一个名称b:imported。我手头没有IDE,你能试试吗?