i have a problem how to write to a xml file using the xmlpath technology
i have the following file books.xml
text
i need to add to the file it self nodes, for example the E & F nodes how can i do it?
text
Thanks ahead
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
kobi shaalPosted Aug 11, 2007, 3:47 AM
First thanks for replying fast,this is not a home work ,it is a task that my company gave part of a big project.
1.how can i add 2,3,4.... empty nodes E (empty node the hold F) & F (populatet node)as the given example
2.there is one more problem that i cannot figure how can i know if the node i want to add is already there?
Thanks Again
Mike GoldPosted Aug 10, 2007, 6:39 PM
I'm answering this in the hopes that it is not a homework problem, because we discourage putting homework up on the site so you can learn the topic. If this is for work, then I'm sorry I said anything. Either way, I just listed the steps without the code.
text
i need to add to the file it self nodes, for example the E & F nodes how can i do it?
text
You don't need XPath to do what you want, but it can't hurt I suppose
1. Use XmlDocument (Load) to read the file
2. Use XPath (the SelectSingleNode("//A") to get the node you want to add to
3. Add the nodes you are interested in to the selected node using XmlDocuments's CreateNode.
4. Use the Nodes property with the Add method to add the new node.
Use XmlDocument (Save) to save the node