Click to See Complete Forum and Search --> : How can I open an XML File and replace an attribute value?


codeguy03
October 16th, 2009, 03:35 PM
Lets say my value looks like this in the xml file


<<PARTNUMBER Value="352698563 " />


How can I replace that value number?

So far I have this

XmlDocument doc = new XmlDocument();
XmlNode node;


doc.Load(filename);

xpath = string.Format(@".//{0}[@{1}]", "PARTNUMBER" , "Value");
node = doc.DocumentElement.SelectSingleNode(xpath);


it successfully navigates to that node but how do I replace the value?

Arjay
October 17th, 2009, 01:37 AM
Access the XmlAttribute from the following link, and the use its Value property to change the value.

http://msdn.microsoft.com/en-us/library/hk61a712.aspx

codeguy03
October 18th, 2009, 05:35 PM
That tells me how to get to an attribute but doesnt tell me how to set or replace an attribute value. That is where I am stuck at?

Anyone else have an idea?

codeguy03
October 18th, 2009, 05:48 PM
Nevermind I got it

node.Attributes["Value"].Value = ReplacementValue;

Arjay
October 18th, 2009, 07:08 PM
That tells me how to get to an attribute but doesnt tell me how to set or replace an attribute value. That is where I am stuck at?I gave you the link to retrieve the XmlAttribute and then I told you to set the value via the 'Value' property.

yourcode
October 19th, 2009, 04:46 PM
this could help you

http://www.yourcodefactory.com/forum/messages.aspx?TopicID=14

www.yourcodefactory.com/forum