Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search for and modify an XML Node attribute

Status
Not open for further replies.

l3it3r

Programmer
Dec 17, 2004
4
US
I've done some searching over the past few days and I can't seem to find the right answer to this seemingly simple issue.

I just need to be able to find a particular node (there are multiples using the same name) based on an attribute in an XML file and then change one of the attributes.

Example:
Code:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <settings>
     <setting key="dontchange" value="abcde"/>
     <setting key="changethis" value="12345"/>
   </settings>
</configuration>

So, I want to find the 'setting' node with attribute "changethis" and modify the value to "qwerty" from "12345" and then save it, keeping its current formatting. It does NOT need to pass validation, it needs to stay as is for a client application.

Again, I searched, I'm just having a helluva time with this one. Probably simple, but I'm working on many things at the same time and this one is taking too long. Plus, the answer will open up some more things I need to do in the future, so it'll be a win-win when I post some example code :)

Thanks in advance,
Chris
 
That involves steps 1, 2, 3, 4, ... which step do you have trouble with?
 
really, I just need help with finding the node based on an attribute value, changing that value and saving.

It shouldn't take as much looking into for a seemingly simple operation! I could load each line of text and parse it as a string, but I need it to be able to interpret other xml files eventually too, so I'd like to do it 'right'.

thanks
 
>really
It is real. You did not mention even one relevant technology to make the task in context. So you think there is only one context the problem would arise? What is it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top