DocumentElement.AppendChild throws object reference not set to an instance of an object
问题 I'm trying to create a new xml file, write data into it and than save. Here is the code: XmlDocument doc= new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null); doc.AppendChild(dec); XmlElement rootnode = doc.CreateElement("Root"); foreach (var item in list) { XmlElement parent = ordersNIA.CreateElement("ParentElement"); XmlElement childOne = ordersNIA.CreateElement("childOne"); childOne.InnerText = "This is the first child"; parent.AppendChild(childOne);