|
-
October 16th, 2009, 03:35 PM
#1
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?
-
October 17th, 2009, 01:37 AM
#2
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
-
October 18th, 2009, 05:35 PM
#3
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?
-
October 18th, 2009, 05:48 PM
#4
Re: How can I open an XML File and replace an attribute value?
Nevermind I got it
node.Attributes["Value"].Value = ReplacementValue;
-
October 18th, 2009, 07:08 PM
#5
Re: How can I open an XML File and replace an attribute value?
 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.
-
October 19th, 2009, 04:46 PM
#6
Re: How can I open an XML File and replace an attribute value?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|