Frage

Consider these two XML documents:

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>

What namespace should the <b> element be in after inclusion, foo or no namespace?


Using Nokogiri to load the first document with XInclude processing produces a text representation that would imply that <b> is in the parent namespace, but inspecting the elements claims that <b> has no namespace:

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
War es hilfreich?

Lösung

What namespace should the <b> element be in after inclusion, foo or no namespace?

No namespace. XInclude operates at the infoset level and preserves the infoset properties of the included content. The infoset specification explicitly makes the point that

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).

(my bold) - the <b> element is not in a namespace, but its in-scope namespaces infoset property is no longer consistent with the namespace declarations in the "virtual" document that results from resolving the XInclude.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top