I am newbie in LINQ to XML.I have two variable one and two and I want to set these variable values in attribute in XML.
static void Main(string[] args)
{
string one = "first";
string two = "Second";
XDocument doc = XDocument.Load(test.xml);
}
XML
<Root>
<Details XIndex="One" Index="">
<abc></abc>
</Details>
<Details XIndex="Two" Index="">
<xyz></xyz>
</Details>
</Root>
Now please tell me how I can set One and two variables value in Index attribute in details node.
Example – I want below output.
<Root>
<Details XIndex="One" Index="First">
<abc></abc>
</Details>
<Details XIndex="Two" Index="Second">
<xyz></xyz>
</Details>
</Root>
Please tell me.
Thanks in advance.
You can use the
XElement.SetAttributeValue()method: