What I want to happen is that I want to put inside the element whose ID is equal to ParentID? So like in my example the Group whose ParentId=1 should be inside the Group whose Id=1 How can I possibly do this? Got so confused..
As of now here is my code:
XElement xroot = new XElement("Root");
XElement xnavigations = null;
XElement xmenus = null;
foreach (DataRow navigations in GetNavigationSets().Rows)
{
xnavigations = new XElement("Group",
new XElement("GroupName", navigations["name"].ToString())
);
xnavigations.SetAttributeValue("Id", navigations["id"].ToString());
xnavigations.SetAttributeValue("ParentId", navigations["parent_id"].ToString());
foreach (DataRow menus in GetMenusInNavigationSetByNavigation(int.Parse(navigations["id"].ToString())).Rows)
{
foreach (DataRow menu in GetMenuById(int.Parse(menus["menu_id"].ToString())).Rows)
{
xmenus = new XElement("Menu",
new XElement("Name", menu["name"].ToString()),
new XElement("Price", menu["price"].ToString()),
new XElement("Description", menu["description"].ToString())
);
xnavigations.Add(xmenus);
}
}
xroot.Add(xnavigations);
}
xroot.Save("main.xml");
New output: