Hi,
SetAtttribute
won´t create a new attribute for the XElement
. It will just change the value of the specified attribute.
You can try creating this way -
detail.Add(new XAttribute("ProductCount", 1));
The above will create a new ProductCount attribute for the detail XElement. You should also save the xml after you add the new attribute.
Hope this helps.
Edit - BobJanova is right, SetAttributeValye does create a new attribute.