Re: [xml] counting nodes before or after doc is saved?



On Fri, Jul 13, 2007 at 12:52:05PM -0400, Stefan Jeglinski wrote:
If I parse an xml doc from a file, I am able to (using xpath) count 
how many of any particular node (corresponding to the xpath) are in 
the tree, using xpathObj->nodesetval->nodeNr.

But if I am in the middle of creating a tree from scratch, and try to 
count already-created nodes using the same method (using a new 
xpathCtx and xpathObj for each count, so as not to be getting stale 
values), I get nodeNr = 0.

Am I missing some step, or looking at this incorrectly? Does the tree 
somehow have to be "flushed" and "reread" to properly "register" 
nodes (my poor guesses at terminology)? Surely I don't have to write 
the tree out as a file and reparse it...

  XPath operates on the current given tree based usually from the 
root of the document used for creating the context (or from the
context node if the request is relative). There should be no registration
magic, though there is one optimization call possible but it should not
be needed
    http://xmlsoft.org/html/libxml-xpath.html#xmlXPathOrderDocElems

I would have to create simpler sample code that what I have right now 
to try to demonstrate, but I thought I'd post the question alone 
first in case I'm missing the obvious.

  If all the nodes are reachable from the document root they should
be taken into account for the XPath query.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/



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