【发布时间】:2013-12-09 23:24:23
【问题描述】:
我有这个 XML 文件:
<a>
<b>
<name>Ion</name>
</b>
<c>
<article>A10</article>
<price>100</price>
</c>
//here I want to add a new section
<f>....</f>
</b>
</a>
我想添加部分:
<d>
<info1>test</info1>
<info2>test 2</info2>
</d>
在<c> 部分之后,在''之间。
我在 C# 中编写了这段代码来添加定义和添加部分 d:
XDocument doc = XDocument.Load(file.Directory + "//" + file.Name);
XElement newElement = new XElement("d",
new XElement("info1", txtInfo1.Text),
new XElement("info2", txtInfo2.Text)
);
doc.Element("a").Add(newElement);
但是使用这段代码,我在<a> 标记中添加了<d> 部分,我想在<c> 部分之后添加(<a><b><c>...</c><d>...<d/><f>...</f></b></a>)
【问题讨论】:
-
你有结束
</b>标签但是没有开始标签