1
如何複製具有不同名稱的xml部分?
比如我有:複製xml部分
<R id="r4" Name="r 4">
<P>
<Pr id="p3e3" />
<Pr id="p3e4" />
</P>
</R>
我想複製它,但使用不同的名稱和ID,例如:
<R id="copy4" Name="copy 4">
<P>
<Pr id="p3e3" />
<Pr id="p3e4" />
</P>
</R>
我正在使用現有的部分:
IEnumerable<XElement> r = null;
r =
from el in myxml.Root.Elements()
where el.Attribute("id").Value == myvalue
select el;
然後我把它複製:
myxml.Descendants("S").FirstOrDefault().Add(
new XElement("R", new XAttribute("id", GetRandomId()), new XAttribute("Name", "Copyof" + myvalue),
??????? ->how do I copy the content?