DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   XML, XSLT and XPATH (http://www.daniweb.com/forums/forum134.html)
-   -   appending a new node to am existing xml file (http://www.daniweb.com/forums/thread115978.html)

Daljeet Hanspal Mar 27th, 2008 1:15 pm
appending a new node to am existing xml file
 
hi ....
i am trying to add a new node to an existing xml file in c# ..........
the code is as follows:

XmlDocument doc = new XmlDocument();
string filename = @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\xml\xml\bin\Debug\bookstore.xml";
//create a new node
XmlElement newbook = doc.CreateElement("book");

//set attribute
newbook.SetAttribute(label1.Text, textBox1.Text);

//create new element
XmlElement npublication = doc.CreateElement(label2.Text);
npublication.InnerText = textBox2.Text;
newbook.AppendChild(npublication);

XmlNode xn = doc.DocumentElement;
xn.AppendChild(newbook);


i get this message "Object reference not set to an instance of an object."

please help me out


All times are GMT -4. The time now is 4:12 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC