473,503 Members | 4,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to modify value of an attribute?

Hi All
i have a XML file with 12 element named "device", and attribute named
"project". i wanted to change only the value of one attribute. i tried:

XmlNodeList nList = doc.GetElementsByTagName("device");
foreach (XmlNode node in nList)
{
node.Attributes[@"project"].InnerXml = "aaa";
}
but this modified the attribute in all 12 elements, and not in the
specific node.

what can i do?

thanks

Jun 11 '06 #1
1 1279
Hi Shukyh,
i have a XML file with 12 element named "device", and attribute named
"project". i wanted to change only the value of one attribute.

foreach (XmlNode node in nList)
{
node.Attributes[@"project"].InnerXml = "aaa";
}


Your problem is that you are having a foreach loop without any
conditionality. The GetElementsByTagName() method returns a list of nodes
that match the given name. If you loop through them with foreach, then
naturally all the matching nodes will have their attributes changed.

What you need to do is to figure out which node's attribute you want to
change. If you know the index of the node, then you don't need the foreach
loop at all. Otherwise, you would have an if statement inside the loop to
check to see if you are at the correct node.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Jun 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4544
by: little_shoe | last post by:
hi all, I need to modify a label value into a form. I read about the "label" tag but it doesn't seem to have any value attribute. how can I do it using javascript? thanks...
9
1446
by: Carlis | last post by:
I want to make a program that, when you have the mouse on a word, that word is bold... and when you don't have the mouse on that word, the word is not bold. Excuse me for my poor English :-( But...
2
2917
by: S.Sigal | last post by:
Hello: I've seen code in some books for databinding that handles attaching Attributes to Properties during runtime...which is very close (but no cigar) to what I am looking for... The code...
1
263
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I modify the current page in a browser?...
0
7258
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
7313
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
5558
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,...
1
4987
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...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.