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:\Documen ts and Settings\Admini strator\My Documents\Visua l Studio 2005\Projects\x ml\xml\bin\Debu g\bookstore.xml ";
//create a new node
XmlElement newbook = doc.CreateEleme nt("book");
//set attribute
newbook.SetAttr ibute(label1.Te xt, textBox1.Text);
//create new element
XmlElement npublication = doc.CreateEleme nt(label2.Text) ;
npublication.In nerText = textBox2.Text;
newbook.AppendC hild(npublicati on);
XmlElement nisbn = doc.CreateEleme nt(label3.Text) ;
nisbn.InnerText = textBox3.Text;
newbook.AppendC hild(nisbn);
XmlElement ntitle = doc.CreateEleme nt(label4.Text) ;
ntitle.InnerTex t = textBox4.Text;
newbook.AppendC hild(ntitle);
XmlElement nname = doc.CreateEleme nt(groupBox2.Te xt);
newbook.AppendC hild(nname);
XmlElement fname = doc.CreateEleme nt(label5.Text) ;
fname.InnerText = textBox5.Text;
nname.AppendChi ld(fname);
XmlElement lname = doc.CreateEleme nt(label6.Text) ;
lname.InnerText = textBox6.Text;
nname.AppendChi ld(lname);
XmlElement nprice = doc.CreateEleme nt(label7.Text) ;
nprice.InnerTex t = textBox7.Text;
newbook.AppendC hild(nprice);
XmlNode xn = doc.DocumentEle ment;
xn.AppendChild( newbook);
i get this message "Object reference not set to an instance of an object."
please help me out
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:\Documen ts and Settings\Admini strator\My Documents\Visua l Studio 2005\Projects\x ml\xml\bin\Debu g\bookstore.xml ";
//create a new node
XmlElement newbook = doc.CreateEleme nt("book");
//set attribute
newbook.SetAttr ibute(label1.Te xt, textBox1.Text);
//create new element
XmlElement npublication = doc.CreateEleme nt(label2.Text) ;
npublication.In nerText = textBox2.Text;
newbook.AppendC hild(npublicati on);
XmlElement nisbn = doc.CreateEleme nt(label3.Text) ;
nisbn.InnerText = textBox3.Text;
newbook.AppendC hild(nisbn);
XmlElement ntitle = doc.CreateEleme nt(label4.Text) ;
ntitle.InnerTex t = textBox4.Text;
newbook.AppendC hild(ntitle);
XmlElement nname = doc.CreateEleme nt(groupBox2.Te xt);
newbook.AppendC hild(nname);
XmlElement fname = doc.CreateEleme nt(label5.Text) ;
fname.InnerText = textBox5.Text;
nname.AppendChi ld(fname);
XmlElement lname = doc.CreateEleme nt(label6.Text) ;
lname.InnerText = textBox6.Text;
nname.AppendChi ld(lname);
XmlElement nprice = doc.CreateEleme nt(label7.Text) ;
nprice.InnerTex t = textBox7.Text;
newbook.AppendC hild(nprice);
XmlNode xn = doc.DocumentEle ment;
xn.AppendChild( newbook);
i get this message "Object reference not set to an instance of an object."
please help me out
Comment