asp.net XML changing node position

AeroxogShorne

New Member
I'm build xml file:\[code\]public YandexMarketDoc() { var root = _doc.CreateElement("yml_catalog"); root.SetAttribute("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm")); _doc.AppendChild(root); var shop = _doc.CreateElement("shop"); root.AppendChild(shop); Categories = _doc.CreateElement("categories"); shop.AppendChild(Categories); Items = _doc.CreateElement("offers"); shop.AppendChild(Items); }\[/code\]than I add nodes to Categories Node:\[code\]public override void AddCategory(string title, int id, int parent) { var i = Categories.OwnerDocument.CreateElement("category"); i.SetAttribute("id", id.ToString()); if(parent > 0) i.SetAttribute("parentId", parent.ToString()); i.InnerText = title; Categories.AppendChild(i); }\[/code\]but the resulting nodes in Category Node change their positions. This is method for insert node to Category:\[code\]static void FillTemplates(PriceList doc, List<PriceAgregator> price) { foreach (PriceAgregator i in price.Where(r=> r.Level == 0)) { foreach (PriceAgregator level1 in price.Where(r => r.Level == 1 && r.ParentID == i.ID)) { AddCategory(doc, i.Title, level1.ParentID); foreach (PriceAgregator pa in price.Where(r => r.Level == 2 && r.ParentID == level1.ID)) { int p = 0; foreach (PriceAgregatorItem item in pa.Childs) { if (AddItem(doc, item)) p++; } if (p == 0) { RemoveCategory(doc, i.ID); } else { AddCategory(doc, pa.Title, pa.ID, level1.ParentID); } } } } }\[/code\]I think first inserted must category from stroke:AddCategory(doc, i.Title, level1.ParentID);
 
Back
Top