Friday, 8 May 2015

C# xelement change attribute value


<Root>
<Address myatt="abc">NY</Address>
<Address>AUS</Address>
</Root>
if (myXelement.Element("Address").Attribute("myatt").Value == "Abc")
{
myXelement.Element("Address").Attribute("myatt").Value = "XYZ";
}
or
if (myXelement.Element("Address").Attribute("myatt") != null)
{
myXelement.Element("Address").Attribute("myatt").Value = myXelement.Element("Address").Attribute("myatt").Value + " appended;";
}
else
{
myXelement.Element("Address").Add(new XAttribute("myatt", "Added"));
}
view raw gistfile1.cs hosted with ❤ by GitHub