私は以下のコードを持ち、 "sell-product"要素を取得して製品を追加する方法を知りました。入れ子になったxml要素に追加する
XDocument xmlDoc = new XDocument();
xmlDoc.Add(new XElement("users"));
var xml = xmlDoc.Root;
foreach (var user in users)
{
xml.Add(new XElement("user", new XAttribute("first-name", user.FirstName?? ""), new XAttribute("last-name", user.LastName?? ""),
new XElement("sold-products")));
foreach (var product in user.Products)
{
.Add(new XElement("Product",
new XElement("name", product.Name),
new XElement("price", product.Price)));
}
}
XDocumentに関する私の文書をチェックしてください。おそらくあなたの問題を解決することができます:http://stackoverflow.com/documentation/c%23/1528/xmldocument-and-the-system-xml-namespace#t=201704021228091722075 –