Change an XML attribute using C#
-
Hello all, I'm trying to change an attribute in an XML document based on some criteria, I'm using C#, For example I need to do a "search" based on a person's user id, the user id is an attribute of a node name student. if the userid matches a text box I then need to change the Grade attribute of the student. for example, my xml document looks like this I want to 'search' for student 345 and then change the Grade to an 'A' Any help would be greatly appreciated. JC
-
Hello all, I'm trying to change an attribute in an XML document based on some criteria, I'm using C#, For example I need to do a "search" based on a person's user id, the user id is an attribute of a node name student. if the userid matches a text box I then need to change the Grade attribute of the student. for example, my xml document looks like this I want to 'search' for student 345 and then change the Grade to an 'A' Any help would be greatly appreciated. JC
You can select a node in an XmlDocument using Xpath and then use the Attributes collection to access/change an attribute.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
You can select a node in an XmlDocument using Xpath and then use the Attributes collection to access/change an attribute.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Thank you for your help.. How I got it to work. created a new element, assigned the old node to a new node specific to my search criteria
newnode = root.SelectSingleNode("Students/Student/[@userid='" + loginform.userid + "']");
I then created a new attribute and used the append function to add the newly created attribute as the last attribute. saved the document... and it worked.. hope this help someone.... thanks again. JC