469,948 Members | 2,916 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,948 developers. It's quick & easy.

read file xmlreader and writer xmlwriter after root node

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
Oct 9 '09 #1
2 4405
3,525 Expert 2GB
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
1,501 Expert 1GB
For working with XML files, I'd highly recommend the XmlDocument class, and accompanying XmlNode classes.


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.

Similar topics

8 posts views Thread by Garyrek | last post: by
3 posts views Thread by Michael Malinak | last post: by
1 post views Thread by Chua Wen Ching | last post: by
reply views Thread by XML newbie: Urgent pls help! | last post: by
reply views Thread by jakerad1979 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.