【发布时间】:2013-10-16 01:11:14
【问题描述】:
以下 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>-元素显式(!)放入'null-namespace':<Bar xmlns="">。
我不明白为什么应该期望一个空命名空间元素。该模式为所有元素定义了一个命名空间,对于<Foo>-元素,验证器确实需要f2b-命名空间。但即使我像上面那样在<Bar>-element 定义中明确设置命名空间,验证器仍然期望xmlns="" 用于Bar-element。
我尝试了架构和文档的几种变体,但没有找到答案 - 我根本无法猜测为什么在这种特殊情况下需要空命名空间。
任何提示表示赞赏...... ekke
【问题讨论】:
标签: xml xsd xml-namespaces