By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,510 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,510 IT Pros & Developers. It's quick & easy.

read file xmlreader and writer xmlwriter after root node

P: 1
Hello,
first i am creating xml file if file does not exist.
Expand|Select|Wrap|Line Numbers
  1. String myFile = "C:\myxmlfile.xml"; 
  2. if (!File.Exists(myFile)) { 
  3. using (FileStream conStream = new FileStream(myFile, FileMode.Create, FileAccess.Write)) { 
  4. XmlWriter conWriter = new XmlTextWriter(conStream, Encoding.UTF8); 
  5. conWriter.WriteStartDocument(); 
  6. conWriter.WriteStartElement("myrootnode"); 
  7. conWriter.WriteStartElement("myfirstnode"); 
  8. conWriter.WriteEndDocument(); 
  9. conWriter.Close(); 
  10. conStream.Close(); 
  11. else 
  12. here read file which i just created in above code and write after new entries after root node, How to implement it or How to search for rootnode and attach new entries after root node? 
  13. Any help would be highly appreciated. 
  14. Thanks 
Best Regards
Adnan
Oct 9 '09 #1
Share this Question
Share on Google+
2 Replies


tlhintoq
Expert 2.5K+
P: 3,525
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Oct 9 '09 #2

GaryTexmo
Expert 100+
P: 1,501
For working with XML files, I'd highly recommend the XmlDocument class, and accompanying XmlNode classes.

http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx
http://msdn.microsoft.com/en-us/libr...l.xmlnode.aspx

The thing to know is that XML in an XmlDocument object is set up as a hierarchical node structure... think a TreeView object. So once you read your XML text into the XmlDocument object, you can traverse through the ChildNodes recursively.

Play around with it and see what you can find out :)
Oct 9 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.