in reply to XML::XPath printToFile function?

Thanks for the replies. I'm sure this would be better as a new post but the short of what I am trying to do is this. Add elements to nodes based on the attribute value or create a new file if it does not exist. The basic file would be this.
<root> <node id = "1"> <request> <question> ... </question> </request> </node> </root>
Answers would be appended to the node with a matching id.
<root> <node id = "1"> <request> <question> ... </question> </request> <reply> <answer> ... </answer> </reply> <reply> <answer> ... </answer> <reply> </node> </root>
I would also like to remove nodes based on the id attribute. And be able to do all this through a Jabber bot similar to Peter Saint-Andre's surveyor.