Please refer to the following sample to update the value of XML attribute.
XDocument xdoc = XDocument.Load(Server.MapPath("NavigationDetails.xml"));
foreach (var element in xdoc.Descendants("NavigationDetails"))
{
string MenuOrder = element.Attribute("MenuOrder").Value.ToString();
if (MenuOrder=="")
{
element.Attribute("MenuOrder").Value = "1";
}
}
xdoc.Save(Server.MapPath("NavigationDetails.xml"));
Best Regards,
Fei Han
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
186 Points
357 Posts
How to update node value in XML?
Apr 16, 2015 04:42 AM|maheshvishnu|LINK
I have a string like "<NavigationDetails Title=\"Nw\" Description=\"Nw\" NavigateTo=\"Nw\" ImageUrl=\"\" MenuOrder=\"\" />"
i want to update MenuOrder value to 1 if it's value is null or empty.How to do this?
Contributor
2842 Points
767 Posts
Re: How to update node value in XML?
Apr 16, 2015 05:09 AM|mshoaiblibra|LINK
Parse this string in XmlDocument.
Then add value:
M Shoaib Waheed
MCSD & MCPD [Web Development 4.0]
http://shoaib.pk
All-Star
40565 Points
6233 Posts
Microsoft
Re: How to update node value in XML?
Apr 17, 2015 01:27 AM|Fei Han - MSFT|LINK
Hi maheshvishnu,
Thanks for your post.
Please refer to the following sample to update the value of XML attribute.
Best Regards,
Fei Han