我有一个 XML 文件:
<Root>
<Lv1>
<1_Data_Lv2_1>A1</1_Data_Lv2_1>
<2_Data_Lv2_1>A2</2_Data_Lv2_1>
</Lv1>
<Lv1>
<1_Data_Lv2_1>B1</1_Data_Lv2_1>
<2_Data_Lv2_1>B2</2_Data_Lv2_1>
</Lv1>
</Root>
C#
using (var myStream = new IsolatedStorageFileStream("Settings.xml", FileMode.Open, myIsolatedStorage))
{
xdoc = XDocument.Load(myStream);
}
var lv1s = from lv1 in xdoc.Elements("Root")
select new
{
Children = lv1.Descendants("Lv1")
};
foreach (var lv1 in lv1s)
{
foreach (var lv2 in lv1.Children)
{
MessageBox.Show(Convert.ToString(lv2.Value));
}
}
如何获取 <1_Data_Lv2_1> == "A1" 的所有节点 lv1 并写入另一个 xml?