我试图将这些 node price
、qty
、amount
插入子体Apple
>;Store
仅使用属性查找插入的确切位置.
<?xml version="1.0" encoding="utf-8"?>
<Fruits>
<node text="Apple" tag="a" imageindex="0">
<node text="Store" tag="b" imageindex="1" />
<node text="City" tag="c" imageindex="2" />
</node>
<node text="Orange" tag="a" imageindex="0">
<node text="Store" tag="b" imageindex="1" />
<node text="City" tag="c" imageindex="2" />
</node>
</Fruits>
预期结果:
<?xml version="1.0" encoding="utf-8"?>
<Fruits>
<node text="Apple" tag="a" imageindex="0">
<node text="Store" tag="b" imageindex="1" />
<node text="price" tag="b" imageindex="1" />
<node text="qty" tag="b" imageindex="1" />
<node text="amount" tag="b" imageindex="1" />
<node text="City" tag="c" imageindex="2" />
</node>
<node text="Orange" tag="a" imageindex="0">
<node text="Store" tag="b" imageindex="1" />
<node text="City" tag="c" imageindex="2" />
</node>
</Fruits>
以下是我到目前为止所做的.我很难使用该属性定义detail
路径.我知道Linq to XML
有一个直接的方法,但无法理解.虽然我试了foreach
次,但没有成功,至少对我来说,它变得更复杂了.
XElement xFruit = XElement.Load(@"D:\Xml\Fruit.xml");
XElement detail = xFruit...
detail.Add(
new XElement("price", "$10"),
new XElement("qty", "10"),
new XElement("amount", "$100")
);
xFruit.Save(@"D:\Xml\Fruit.xml");
任何帮助都将不胜感激!