以下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>
Run Code Online (Sandbox Code Playgroud)
架构:
<?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>
Run Code Online (Sandbox Code Playgroud)
当我根据模式验证文档时,我在<f2b:Bar>-element 上收到一条错误消息,说明这<f2b:Bar>是不期望的.为使文件有效我必须把<Bar>-元素明确进入"空命名空间"(!) <Bar xmlns="">.我不明白为什么应该期望null-namespaced元素.该架构定义的所有元素和对命名空间<Foo>-元素的f2b-命名确实是验证预期.但是,即使我明确设置命名空间中<Bar>-元素定义,就像我上面那样,验证仍预计xmlns=""为Bar -元素.我尝试了架构和文档的几种变体来找到一个没有运气的答案 - 我简直无法猜测为什么在这种特殊情况下会出现空命名空间.
任何暗示都赞赏... ekke