Linq to XML Dodaj element do określonego drzewa podrzędnego
Mój 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>
Chcę dodać nowy element konta, aby powiedzieć klientowi o identyfikatorze 2. Wiem, jak dodać linię, czego nie wiem, jak określić klienta (gdzie mam wpisać identyfikator klienta?)
Mój kod 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");
Dzięki za pomoc. XML nie jest moim dobrym przyjacielem :(