How can I open an XML File and replace an attribute value?
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?
Re: How can I open an XML File and replace an attribute value?
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
Re: How can I open an XML File and replace an attribute value?
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?
Re: How can I open an XML File and replace an attribute value?
Nevermind I got it
node.Attributes["Value"].Value = ReplacementValue;
Re: How can I open an XML File and replace an attribute value?
Quote:
Originally Posted by
codeguy03
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.
Re: How can I open an XML File and replace an attribute value?