C# 如何在C中向XmlDocument()的根节点添加属性#
我在C#中已经有一个XmlDocument对象。假设InnerXml看起来像这样C# 如何在C中向XmlDocument()的根节点添加属性#,c#,xmldocument,document-root,xml-attribute,C#,Xmldocument,Document Root,Xml Attribute,我在C#中已经有一个XmlDocument对象。假设InnerXml看起来像这样 <MyResponse> <ResponseType> <Id>8825</Id> </ResponseType> </MyResponse> 8825 如何添加名称为uuid、值为781283721381的属性,例如uuid=“781283721381”。因此,我的Xml输出如下所示: <MyResponse uu
<MyResponse>
<ResponseType>
<Id>8825</Id>
</ResponseType>
</MyResponse>
8825
如何添加名称为uuid、值为781283721381的属性,例如uuid=“781283721381”。因此,我的Xml输出如下所示:
<MyResponse uuid="781283721381">
<ResponseType>
<Id>8825</Id>
</ResponseType>
</MyResponse>
8825
是的,XmlDocument有点难以修改,这就是XDocument被发明的部分原因。但是使用XML序列化和处理对象是最容易的
document.DocumentElement.Attributes.Append(document.CreateAttribute("uuid")).Value = "12345"