Skip to content

Instantly share code, notes, and snippets.

@Microsofttechies
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save Microsofttechies/5f40662980981b8d122d to your computer and use it in GitHub Desktop.

Select an option

Save Microsofttechies/5f40662980981b8d122d to your computer and use it in GitHub Desktop.
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"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment