如何修改XElement的内容?

mjs*_*jsr 6 c# linq-to-xml

有一种简单的方法来修改XElement的InnerXml吗?我们有这个非常简单的xml

<planets>
    <earth></earth>
    <mercurio></mercurio>
</planets>
Run Code Online (Sandbox Code Playgroud)

并且我们想要将来自另一个来源的xml附加<continents><america/><europa/>.....blablabla到地球节点中,该字符串就像一个字符串" ".

我读了相关的问题,但他们谈到检索XElement的innerxml,我不明白如何"修改"实际的Xelement :(

Cha*_*ion 4

构建 XML

planetsElement.Element("earth").Add(
    new XElement("continents",
        new XElement("america"),
        new XElement("europa")
    )   
);
Run Code Online (Sandbox Code Playgroud)

解析并添加

planetsElement.Element("earth").Add(
   XElement.Parse("<continents><america/><europa/></continents>")
);
Run Code Online (Sandbox Code Playgroud)