Re: [xml] Relative paths in XPointer



Daniel Veillard wrote:
On Wed, Feb 25, 2004 at 09:45:37PM +0100, Manuel González Castro wrote:
Hi,

The "XPointer xpointer() Scheme Working Draft"
(http://www.w3.org/TR/xptr-xpointer/) says that the function "here()"
can be used to point locations using relative paths. I'm trying to get
it working with xmllint, but I'm getting errors whenever I use XInclude
with XPointer relative paths.    

I haven't seen any bug related to this error, and I think my xpointer
expressions are correct. 

So, does libxml support "here()" and other relative-path functions like
"parent::*" inside xpointer expressions? 

I'm using xmllint built on W2K from today CVS, and here are the
testcases: 

---------------------------------------------------------------------
[...]
---------------------------------------------------------------------
And this is the same with an xpointer relative path:

D:\tests>type xpointer_relative.xml

<a>
  <b id="1"/>
  <b id="2"/>
  <c>
    <xi:include
  xpointer="xpointer(here()/parent::*/parent::*/b[ id='1'])"
xmlns:xi="http://www.w3.org/2003/XInclude"/> </c> </a>
[...]
Any hint?

  You're playing with fire. The problem is what here() should be pointing
to. Assuming no XInclude processing and an evaluation of XPointer in the
document XPath data model of the given document, then here() should
probably 
point to the xi:include element.
  Now the problem is that you're running on an XIncluded document. As
part 
of the XInclude processing the xi:include element is discarded and
replaced 
by the evaluation of the include selection. And that selection start on
an 
element which doesn't exists anymore.

Can the processor evaluate the xpointer expression before replacing the xi:include with the result of the 
evaluation? This would solve the problem, at least in libxml. 

  I don't think it's a good idea to try to match XPointer here() and
XInclude processing, since basically there is a deep conflict between
both, and I doubt you will end up with a reliable solution in any case.

Anyway, my problem is solved (in fact, I had no problem at all). I was trying to use relative paths in 
xpointer when including a fragment of the self document because I was afraid of problems with absolute paths 
when chaining inclusions, but I've tested it and there is no problem.

If anybody is interested:

A document including a fragment of itself with an absolute path:

D:\tests>type included.xml

<model>
  <item id="1">I want this</item>
  <item id="2"/>
  <group>
    <xi:include xpointer="xpointer(/model/item[ id='1'])" xmlns:xi="http://www.w3.org/2003/XInclude"/>
  </group>
</model>

Resolve includes, everything is fine:

D:\tests>xmllint --xinclude included.xml
<?xml version="1.0"?>
<model>
  <item id="1">I want this</item>
  <item id="2"/>
  <group>
    <item id="1">I want this</item>
  </group>
</model>

Now include the first doc in a second one, which has an element that matches the absolute path given in the 
first doc (/model/item[ id='1']):

D:\tests>type includer.xml

<model>
  <item id="1">I don't want this</item>
  <item id="2"/>
  <submodel>
    <xi:include href="included.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
  </submodel>
</model>

Resolve includes and everything is fine again:

D:\tests>xmllint --xinclude includer.xml
<?xml version="1.0"?>
<model>
  <item id="1">I don't want this</item>
  <item id="2"/>
  <submodel>
    <model>
  <item id="1">I want this</item>
  <item id="2"/>
  <group>
    <item id="1">I want this</item>
  </group>
</model>
  </submodel>
</model>

Great library!

Thanks,
Manuel





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]