hello there!
i have a problem how to write to a xml file using the xmlpath technology
i have the following file books.xml
text
textg
99999
i need to add to the file it self nodes, for example the E & F nodes how can i do it?
text
textg
99999
0000
Thanks ahead
Add node to xml file
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Mike GoldRank #50 · 30.6K pointsPosted Aug 10, 2007, 2:39 PM EDT
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
textg
99999
i need to add to the file it self nodes, for example the E & F nodes how can i do it?
text
textg
99999
0000
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
kobi shaal16 pointsPosted Aug 10, 2007, 11:47 PM EDT
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