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 http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
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:
BEFORE:
NEW_USER_NODE_NS_HREF = NULL;
NEW_USER_NODE_NS_PREFIX = NULL;
xmlNodePtr retPtr = xmlNewChild(userParentPtr,
xmlNewNs(userParentPtr,
xmlCharStrdup(NEW_USER_NODE_NS_HREF),
xmlCharStrdup(NEW_USER_NODE_NS_PREFIX)),
BAD_CAST "user",
NULL);
AFTER:
xmlNodePtr retPtr = xmlNewChild(userParentPtr,
NULL,
xmlCharStrdup(USER_TAG),
NULL);
|