How can I modify an xml value based on the attribute value.

Posted on 2011-03-22
Last Modified: 2012-05-11
It does not look like its as easy as selectsinglenode. I could be wrong though.

XmlDocument xmldoc = new XmlDocument();

        <property name="index1">myvalue1</property>
        <property name="index2">myvalue2</property>
        <property name="index3">myvalue3</property>

To.... (notice index2 value has changed)

        <property name="index1">myvalue1</property>
        <property name="index2">myvalue2-MODIFIED</property>
        <property name="index3">myvalue3</property>
Question by:silentthread2k
LVL 52

Accepted Solution

Carl Tawn earned 500 total points
Comment Utility
You should be able to do something like:
XmlNode node = xmldoc.SelectSingleNode("/root/properties/property[@name='index2']");
if (node != null)
    node.InnerText = node.InnerText + "-MODIFIED";

// save document, etc

Open in new window

LVL 11

Expert Comment

by:Sudhakar Pulivarthi
Comment Utility
You can also do it with InnerXml property also.
node.InnerXml= node.InnerXml+ "-MODIFIED";

Author Closing Comment

Comment Utility

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now