我的 XML:
<Bank>
<Customer id="0">
<Accounts>
<Account id="0" />
<Account id="1" />
</Accounts>
</Customer>
<Customer id="1">
<Accounts>
<Account id="0" />
</Accounts>
</Customer>
<Customer id="2">
<Accounts>
<Account id="0" />
</Accounts>
</Customer>
</Bank>
我想添加新的 Account 元素,让我们说 ID 为 2 的客户。我知道如何添加我不知道如何指定客户的行(我在哪里写客户的 ID?)
我的 LINQ to XML 代码:
XDocument document = XDocument.Load("database.xml");
document.Element("Bank").Element("Customer").Element("Accounts").Add
(
new XElement
(
"Account", new XAttribute("id", "variable")
)
);
document.Save("database.xml");
谢谢您的帮助。XML 不是我的好朋友 :(