473,414 Members | 1,636 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,414 software developers and data experts.

C# updating xml element

chathura86
227 100+
hi, i want to update a xml element.i used the following code

Expand|Select|Wrap|Line Numbers
  1. System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
  2. System.Xml.XmlNode xmlUpdateNode;
  3.  
  4. xmlDoc.Load("XML//App_Var_Data.xml");
  5. xmlUpdateNode = xmlDoc.SelectSingleNode("NAME");
  6. xmlUpdateNode.InnerText = "chathura";
  7. xmlDoc.Save("XML//App_Var_Data.xml");
  8.  
when i execute i get the following exception
Object reference not set to an instance of an object.

please help pme to solve this problem

chathura bamunusinghe
Dec 4 '07 #1
4 4803
mzmishra
390 Expert 256MB
The main cause for this type of error is
1. nOt declaring variable
2. Bad scope of the variable
3.Bad inits/constructs


Just check you ahve done all these correctly and also let us know which line is throwing the exception
Dec 4 '07 #2
Shashi Sadasivan
1,435 Expert 1GB
Hi,
Could you please provide which line throws that exception?
I would assume that the following line throws the exception

xmlUpdateNode.InnerText = "chathura";

are you sure that the element NAME exists in the xml document (case sensitive)
If it does is it the root element?

if not, what you need to search online is navigating through an xml document (xpath is your friend here)
Dec 4 '07 #3
chathura86
227 100+
Hi,
Could you please provide which line throws that exception?
I would assume that the following line throws the exception

xmlUpdateNode.InnerText = "chathura";

are you sure that the element NAME exists in the xml document (case sensitive)
If it does is it the root element?

if not, what you need to search online is navigating through an xml document (xpath is your friend here)
Yes

xmlUpdateNode.InnerText = "chathura";
throws the exception.

i checked. element NAME exists(in upper case)
so please explain about xpath im new to c#

thanks

chathura bamunusinghe
Dec 4 '07 #4
Shashi Sadasivan
1,435 Expert 1GB
Hi,
Use Online search for tutorials Please....
XPath Tutorial
Manipulate XML data with XPath and XmlDocument
Dec 4 '07 #5

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

Similar topics

5
by: christopher.c.brewster | last post by:
A few years ago my department defined a DTD for a projected class of documents. Like the US Constitution, this DTD has details that are never actually used, so I want to clean it up. Is there any...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
3
by: Asaf | last post by:
Hi, I have a MSSQL 2005 test DB with two tables: Table "T1Customers": T1CustomersRowEnum (PK, int, Not Null) T1CustomersFullName (nvarchar(50) null) Table "T2Details":
13
by: mfreeman | last post by:
The minimal code (VB.NET 2003) needed to show this problem is shown below. All I do is loop through the records in the table and update them without making any changes. Out of 600 records, about...
2
by: Rob Long | last post by:
Hi I have an HTML select element in my page and it's multiple property is disabled (one item at a time mode) but I still want to transfer all the items in the select to the server when the form...
1
by: explode | last post by:
My table has 5 columns: Broj iksice, Prezime, Ime, Broj indeksa, Broj pohadjanja. This is the code in the dataset designer VB made it by it self: Private Sub InitClass() Me.columnBroj_iksice =...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
9
by: mevryck | last post by:
Greetings I have a huge Javascript with inclusion of external scripts and all. I got this by doing a XSLT . Now I have the contents in a Javascript variable, but I'm not able to update the...
3
by: Evan | last post by:
Hello - My script use a DB file which is written by XML, and the user load this DB file (XML tree in memory), and then do some updating about this tree, such as delete element, generate new...
2
by: Andy | last post by:
I want to dynamically update a list of elements shown as a checkbox list. A file is used to store the elements, and elements can be added and deleted from the list. The trouble is that the window...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.