473,395 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Adding nodes to an 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);

XmlElement nisbn = doc.CreateElement(label3.Text);
nisbn.InnerText = textBox3.Text;
newbook.AppendChild(nisbn);

XmlElement ntitle = doc.CreateElement(label4.Text);
ntitle.InnerText = textBox4.Text;
newbook.AppendChild(ntitle);

XmlElement nname = doc.CreateElement(groupBox2.Text);
newbook.AppendChild(nname);

XmlElement fname = doc.CreateElement(label5.Text);
fname.InnerText = textBox5.Text;
nname.AppendChild(fname);

XmlElement lname = doc.CreateElement(label6.Text);
lname.InnerText = textBox6.Text;
nname.AppendChild(lname);

XmlElement nprice = doc.CreateElement(label7.Text);
nprice.InnerText = textBox7.Text;
newbook.AppendChild(nprice);

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
Mar 27 '08 #1
2 3097
pronerd
392 Expert 256MB
It sounds like your problem is with your language syntax, not XML. You should probably post your question in a form that supports what ever language you are using.

Also you may want to google and review basic forum guidelines. Posts like these generally will not get much of a response. More specific information is needed. For instance when do you get that error? When compiling, at run time? It also looks like the code is incomplete. There are a number of objects that are not defined in the same provided, and there are other objects like filename that never seem to be used.
Mar 27 '08 #2
jkmyoung
2,057 Expert 2GB
Could we see where you are declaring each of the labels, textboxes, etc??

This really seems like something that should be caught in the compiler with a warning.
Mar 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: serge calderara | last post by:
Dear all, I have an application which timely create log file in XML format I ma using the SystemFileWatcher object to monitor creation of new file in the proper path. So far no problem When...
3
by: sho_nuff | last post by:
Question here: I have been trying to find a way to add existing nested nodes to a tree that already has nodes in it: So, my tree looks like this: -com -foo -goo
1
by: Brent Jenny | last post by:
I have an existing xml file taht looks like this. <?xml version="1.0" encoding="utf-8" ?> <Aircraft> <WCOJOItemType type="AircraftType" > <WCJOItemCode>03</WCJOItemCode>...
0
by: Nihar | last post by:
Hello all, I m just trying to add multiple nodes to an existing xml file. Here is my sample. <ADT> <IN1> <DG1> <GT1>
1
by: Bart Steur | last post by:
Hi As a VB6 user I'm unfamiliar with the Treeview control of VB2005. I read it was changed but I have a hard time finding the right help/samples for my problem. In VB6 you had 1 collection,...
2
by: SM | last post by:
Ok, this must be simple but the more i search the more i don't find. It's about SimpleXML and PHP. How to find non-existing nodes or nodes with no text My XML file looks a little bit like this:...
1
by: SM | last post by:
Ok, this must be simple but the more i search the more i don't find. It's about SimpleXML and PHP. How to find non-existing nodes or nodes with no text My XML file looks a little bit like this:...
2
by: michelqa | last post by:
Hi, I'm trying to add nodes to a specific node of a treeview. With VS 2005 and more (>= .net 2.0) I can set the Nodes.Name property and then use Nodes.Find("MyNodeName",true) to add nodes to a...
12
by: blackirish | last post by:
Hi all, I am trying to merge 2 XML files that first of all i need to compare nodes of both files according to 2 attributes in the nodes. If those 3 attributes are equal, i need to replace the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.