Connecting Tech Pros Worldwide Help | Site Map

read file xmlreader and writer xmlwriter after root node

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: Oct 9 '09
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
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,744
#2: Oct 9 '09

re: read file xmlreader and writer xmlwriter after root node


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.
Familiar Sight
 
Join Date: Jul 2009
Location: Calgary, Alberta, Canada
Posts: 211
#3: Oct 9 '09

re: read file xmlreader and writer xmlwriter after root node


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 :)
Reply

Tags
rootnode, xmlreader, xmlwriter