I already have a XmlDocument object in C#. Let's say the InnerXml looks like this;
<MyResponse>
<ResponseType>
<Id>8825</Id>
</ResponseType>
</MyResponse>
How can I add a attribute which has the name as uuid and the value as 781283721381, e.g uuid="781283721381". So my Xml output would look like the following;
<MyResponse uuid="781283721381">
<ResponseType>
<Id>8825</Id>
</ResponseType>
</MyResponse>
document.DocumentElement.Attributes.Append(document.CreateAttribute("uuid")).Value = "12345"
Yeah, XmlDocument is a bit hard to modify, that's part of the reason why XDocument was invented. But it's the easiest to use XML serialization and work on objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With