   [.net] XML reading/writing
  I got a very simple cfml file I'd like to write to, it looks like this:<?xml version='1.0'?><!DOCTYPE controlset SYSTEM "cfml.dtd"><controlset version="1.1.0" language="english" keyboard="us"></controlset>I have been able to iterate through elements in this file using XPath. However, I now wish to write to it and I found something I can't seem to figure out by myself.I am trying to open the file with an XmlDocument, the file opens propperly (as in that it does not generate an exception.But instead of setting the root variable to controlset (XmlNode root = xmlDoc.DocumentElement;), it's set null and the program crashes on with an error saying that the object is not set to a reference on this line: root.AppendChild(control);//....Snippet removed....//  XmlDocument xmlDoc = new XmlDocument();    try  { xmlDoc.Load(reader);   }  catch  { MessageBox.Show("Couldn't load air.cfml");  }  reader.Close();  XmlNode root = xmlDoc.DocumentElement;  XmlElement control = xmlDoc.CreateElement("control");  XmlElement key = xmlDoc.CreateElement("key");  root.AppendChild(control);//....Snippet removed.....//Can anyone tell me what I am doing wrong?   
  Doesn't appear to be anything wrong. You're sure the xml file has in it what you think ("reader" contains what it should)?   ;  well, here is the first part of the code.XmlTextReader reader = new XmlTextReader(docURI);  reader.XmlResolver = null;   XPathDocument doc = new XPathDocument(reader);  XPathNavigator docnav = doc.CreateNavigator();  XPathNodeIterator itr = docnav.Select("/controlset/control");  while (itr.MoveNext())  { if (itr.Current.GetAttribute("function", "").Trim() == "flap control") {return; }  }this works, if I add a element called control with the attribute function that is equal flap control the debugger gets an hit on the return statement.so this seems to work.[edit]Never mind, I solved the problem. I had to redeclare the XmlReader when using it again.thank you.[Edited by - kappa on May 26, 2006 3:19:28 PM]