-2

假设我们有 XML 文件: <COLLEGE> <location> <area> najafgrah </area> <!--want to add new child node pragmatically--> </location> </COLLEGE>

如何添加新的子节点......

4

2 回答 2

1

这是一个例子。

XElement doc = XElement.Parse(@"<COLLEGE> <location> <area> najafgrah </area>
</location> </COLLEGE>");

doc.Add(new XElement("location", new XElement("area", "area number 2")));
于 2013-04-22T08:06:55.733 回答
0

XElement 有一个添加节点的 Add 方法。您必须导航到 COLLEGE/location 并调用此节点上的方法。

XElement.Add

于 2013-04-22T07:57:39.053 回答