I have below xml file and i want to add new data to a particular element with name TES and
<product ip="3,4,4,4,4" op="33" />
<?xml version="1.0" encoding="utf-8"?>
<root>
<Brand name="TES">
<product ip="40,67, 0,0,0" op="0" />
<product ip="49,25, 4,4,0" op="0" />
<product ip="40,5, 3,64,0" op="0" />
<product ip="85,27, 6,6,0" op="0" />
<product ip="8,27, 6,6,0 " op="0" />
<product ip="23,5, 4,1,0" op="0" />
<product ip="26,25,0,33,10" op="0" />
<product ip="100,0,0,0,0" op="0" />
</Brand>
<Brand name="SW">
<product ip="0, 1, 0,0,0" op="1" />
<product ip="0, 100,0,0,0" op="1" />
<product ip="0, 25,0,75,0" op="1" />
<product ip="0, 25,0,75,0" op="1" />
<product ip="0, 35,0,55,0 " op="1" />
<product ip="42, 43,0,82,6" op="1" />
<product ip="24, 7,1,17,0" op="1" />
</Brand>
</root>
What I have tried:
i had tried below c# but it only add attributes to first existing element
XElement root = XElement.Load("sample.xml");
root.Element("Brand").Element("product").Add( new XAttribute("IP", "3,4,4,4,4"),new XAttribute("OP", "33"));
root.Save("output.xml");