Re: [xml] XPath/Document concurrency issue



On Sat, Feb 23, 2008 at 03:05:27AM +0100, Belgabor wrote:
Hi everybody,

I have a strange problem which I can only describe as a concurrency 
issue between the (xml) document content and the results I get from 
XPath queries. I'm working on a project where I plan to use the 
Model/Controller/View architecture, the model being a parsed xml tree 
and read/write access to it is mainly done via XPath queries. Therefore 
I'm quite worried by this issue.

Here's what I do:

- Read xml document
- Create an XPath context (xmlXPathNewContext)
- Run a query (xmlXPathEvalExpression), getting a result node
- Create a new node (xmlNewNode), set content (xmlEncodeSpecialChars, 
xmlNodeSetContent)
- Add new node as child to the result node (xmlAddChild)

Later:
- Create an XPath context (xmlXPathNewContext) with the same document
- Run a query (xmlXPathEvalExpression) which checks for the content of 
the node added above in a predicate.
- Get no result.

The curious thing is (and the reason why I bring it here rather than 
think it's an issue of the c++ wrapper around libxml2 I wrote) that 
after I save the document to disk and reload it, everything works as 
expected.

  My guess is that when you modify the tree you build it wrong (I'm guessing
you're using namespaces and not properly building your tree), the output
once serialized looks fine, but the internal tree structures are wrong.
That would lead to XPath failing on the modifed tree and but succeeding
when serializing/parsing. Triple check all the pointers and namespaces
generated when using xmlAddChild.

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]