Re: [xml] XPath query failing on modified xmlDoc

Cory Virok wrote:
Ok, I'm new to libxml2 in general so there's probably a very simple solution to this problem, (haven't been able to find it in the archives though.)

I have an xml document that I load up and modify. In this particular instance, I load the document and then add in a new child element. I have verified that the child is in the doc by doing a quick xmlDocDump(). After I add children I want to be able to remove them. The problem I'm seeing is that when I do an XPath query for the children that existed prior to loading the document everything's fine, but when I query for the children that I just added I get back an empty node set.

I remake the XPath context using the same doc pointer each time I query so I know that the xpath context is using the right doc... It seems like the DOM tree hasn't been updated and thus the xpath query cannot find the child nodes, but I've verified that the tree is up-to-date...

The only thing I can think of is the format of my xpath _expression_, which does not use explicit '[1]' or 'descendant::' etc...

/config/user-list/user[ nickname="NICKNAME"]

Any help is appreciated.

- Cory Virok
xml mailing list, project page
xml gnome org

For all interested, I found the problem... it wasn't very obvious to me.

Turns out that the problem was adding in the child node with a namespace object who's PREFIX and HREF were both NULL. Had I created the child element with a NULL namespace altogether the xpath would have worked correctly. I just assumed that NULL prefix and href would be the same as a NULL namespace. Guess I was wrong.

Here's the code:

xmlNodePtr retPtr = xmlNewChild(userParentPtr,
                    BAD_CAST "user",


xmlNodePtr retPtr = xmlNewChild(userParentPtr,

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