473,651 Members | 3,011 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.GetElements ByTagName("devi ce");
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 1292
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 GetElementsByTa gName() 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***@removethi s.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
4551
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
1463
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 the program doesn't work properly. Does somebody know why? This is the program: <html> <head> <script language="javascript">
2
2925
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 in the book was basically the following: override protected void PreFilterProperties(IDictionary properties) {
1
263
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I modify the current page in a browser? ----------------------------------------------------------------------- Using the DOM and Microsoft's innerHTML extension, the following would be sufficient to modify the content of any element that can have content: `` <div id="anID">Some Content</div'' with script of ``...
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8278
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8701
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8584
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7299
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.