gpt4 book ai didi

xml - 为什么 'null-namespace' 对于定义为 'have' 的 xml 元素是架构中的命名空间?

转载 作者:数据小太阳 更新时间:2023-10-29 01:58:03 24 4
gpt4 key购买 nike

以下 xml 文档和模式是从一​​个更大的模式中提炼出来的,问题首先发生在这个模式中:

xml文件:

<f2b:Foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:f2b="http://www.outerfoospace.com/schemas/foo2bar" xsi:schemaLocation="http://www.outerfoospace.com/schemas/foo2bar f2b-0-0-0.xsd">
<f2b:Bar>text</f2b:Bar>
</f2b:Foo>

架构:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f2b="http://www.outerfoospace.com/schemas/foo2bar" targetNamespace="http://www.outerfoospace.com/schemas/foo2bar">
<xs:complexType name="T_Foo">
<xs:sequence>
<xs:element name="Bar" xmlns="f2b"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Foo" type="f2b:T_Foo"/>
</xs:schema>

当我根据架构验证文档时,我在 <f2b:Bar> 上收到一条错误消息-元素说<f2b:Bar>不是预期的。为了使文档有效,我必须将 <Bar> -元素显式(!)进入“空命名空间”:<Bar xmlns=""> .我不明白为什么应该期望一个空命名空间元素。该架构为所有元素和 <Foo> 定义了一个 namespace 。 -元素 f2b -命名空间确实是验证器所期望的。但即使我在 <Bar> 中显式设置命名空间-元素定义就像我上面做的那样,验证器仍然期望 xmlns=""对于 Bar -元素。我尝试了模式和文档的几种变体来找到答案,但没有成功 - 我根本无法猜测为什么在这种特殊情况下会出现 null 命名空间。

任何提示表示赞赏...... ekke

最佳答案

简短回答:将 elementFormDefault="qualified" 添加到架构的根 xs:schema 标记中。

更长的答案:默认情况下,只有顶级“全局”元素声明采用模式的目标命名空间。复杂类型中的“本地”元素声明不在命名空间中。您可以使用 xs:element 标记上的 form 属性为一个特定的本地元素覆盖此设置,或者使用 elementFormDefault 上的所有元素全局覆盖此设置xs:schema.

关于xml - 为什么 'null-namespace' 对于定义为 'have' 的 xml 元素是架构中的命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19259111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com