考虑这两个 XML 文档:
a.xml
<a xmlns="foo" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="b.xml" parse="xml" />
</a>
b.xml
<b>Hi Mom!</b>
<b>
应该使用什么命名空间元素在包含之后,foo
或者没有命名空间?
使用Nokogiri使用 XInclude 处理加载第一个文档会生成一个文本表示形式,该表示形式暗示 <b>
位于父命名空间中,但检查元素后发现 <b>
没有命名空间:
require 'nokogiri'
d = Nokogiri.XML(IO.read('a.xml'),&:xinclude)
puts d
#=> <?xml version="1.0"?>
#=> <a xmlns="foo" xmlns:xi="http://www.w3.org/2001/XInclude">
#=> <b>Hi Mom!</b>
#=> </a>
p d.root.namespace
#=> #<Nokogiri::XML::Namespace:0x3fd40c517de8 href="foo">
p d.root.elements.first.namespace
#=> nil
最佳答案
What namespace should the
<b>
element be in after inclusion, foo or no namespace?
没有命名空间。 XInclude 在信息集级别运行并保留所包含内容的信息集属性。 infoset specification明确指出这一点
An information set corresponding to a real document will necessarily be consistent in various ways; for example the [in-scope namespaces] property of an element will be consistent with the [namespace attributes] properties of the element and its ancestors. This may not be true of an information set constructed by other means; in such a case there will be no XML document corresponding to the information set, and to serialize it will require resolution of the inconsistencies (for example, by outputting namespace declarations that correspond to the namespaces in scope).
(我的粗体)- <b>
元素不在命名空间中,但其范围内命名空间信息集属性不再与解析 XInclude 所产生的“虚拟”文档中的命名空间声明一致。
关于ruby - XInclude 包含元素的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14542030/