Re: [xml] Line numbers and XInclude
- From: Daniel Veillard <veillard redhat com>
- To: Michael Day <mikeday yeslogic com>
- Cc: xml gnome org
- Subject: Re: [xml] Line numbers and XInclude
- Date: Wed, 15 Sep 2010 11:14:12 +0200
On Mon, Sep 13, 2010 at 12:07:01PM +1000, Michael Day wrote:
Hi,
After performing XInclude processing is there any way of identifying
which nodes in the tree came from which file originally?
Well, there is but it's not completely trivial.
First normally XInclude should now add a base attribute to the XIncluded
top elements (unless disabled) and that should be sufficient, for
example xmlNodeGetBase() should work in that case. Of course there
is always the possibility to XInclude non-elements and that defeats
this.
The other possibility is that libxml2 XInclude keeps the original
<xi:include> elements but turns them into XML_XINCLUDE_START nodes,
it also adds an XML_XINCLUDE_END element to mark the end of the
included block, so an algorithm like
for all node n in the node ancestors
for all nodes l in the n predecessors
if l type is XML_XINCLUDE_END
break (next ancestor)
if l type is XML_XINCLUDE_START
that's the xi:xinclude node for the node
you may have to recurse as XInclude can cascade, but basically you get
the full informations kept in the tree. Finding back the actual URI for
each can be a bit painful due to the recursion but that should be
possible.
The reason I ask is that it can be convenient to have file and line
number information for error messages, but it seems that XInclude
will result in a document containing nodes with line numbers that
are from a different file, leading to user confusion.
xmlNodeGetBase() should get it right at least if the xml:base
attributes are kept.
Is there any workaround for this other than implementing XInclude
resolution "by hand"?
I think the 2 methods above provide an heuristic and the possibility
for an exact algorithm :-)
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel veillard com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]