/// <summary> /// Reads page item from Xml element and adds it as a child to the parent. /// </summary> /// <param name="parent"></param> /// <param name="categoryNode"></param> private void _AddPageItem(CategoryItem parent, XmlElement categoryNode) { PageItem newPage = new PageItem(); string typeName = categoryNode.GetAttribute(XML_TYPE_ATTRIBUTE_NAME, ""); newPage.PageType = Type.GetType(typeName); // page type should exist Debug.Assert(newPage.PageType != null); // add new page to the parent newPage.Parent = parent; parent.AddChild(newPage); }
/// <summary> /// Reads category item from Xml element and adds it as a child to the parent. /// </summary> /// <param name="parent"></param> /// <param name="categoryNode"></param> private void _AddCategoryItem(CategoryItem parent, XmlElement categoryNode) { bool visible = true; if (null != categoryNode.Attributes[XML_VISIBLE_ATTRIBUTE_NAME]) { visible = bool.Parse(categoryNode.Attributes[XML_VISIBLE_ATTRIBUTE_NAME].Value); } CategoryItem newCategory = new CategoryItem(visible); newCategory.Name = categoryNode.GetAttribute(XML_NAME_ATTRIBUTE_NAME, ""); string captionID = categoryNode.GetAttribute(XML_CAPTIONID_ATTRIBUTE_NAME, ""); newCategory.Caption = (string)App.Current.FindResource(captionID); string typeName = categoryNode.GetAttribute(XML_TYPE_ATTRIBUTE_NAME, ""); newCategory.CategoryType = Type.GetType(typeName); // add new category to the parent newCategory.Parent = parent; parent.AddChild(newCategory); // process all other category childs foreach (XmlNode node in categoryNode.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; // skip comments and other non element nodes } if (node.Name.Equals(XML_CATEGORY_ELEMENT_NAME, StringComparison.OrdinalIgnoreCase)) { _AddCategoryItem(newCategory as CategoryItem, node as XmlElement); } else if (node.Name.Equals(XML_PAGE_ELEMENT_NAME, StringComparison.OrdinalIgnoreCase)) { _AddPageItem(newCategory as CategoryItem, node as XmlElement); } else { throw new NotSupportedException(); } } }
/// <summary> /// Reads page item from Xml element and adds it as a child to the parent. /// </summary> /// <param name="parent"></param> /// <param name="categoryNode"></param> private void _AddPageItem(CategoryItem parent, XmlElement categoryNode) { PageItem newPage = new PageItem(); string typeName = categoryNode.GetAttribute(XML_TYPE_ATTRIBUTE_NAME, ""); newPage.PageType = Type.GetType(typeName); // page type should exist Debug.Assert(newPage.PageType != null); // add new page to the parent newPage.Parent = parent; parent.AddChild(newPage); }
/// <summary> /// Reads category item from Xml element and adds it as a child to the parent. /// </summary> /// <param name="parent"></param> /// <param name="categoryNode"></param> private void _AddCategoryItem(CategoryItem parent, XmlElement categoryNode) { bool visible = true; if (null != categoryNode.Attributes[XML_VISIBLE_ATTRIBUTE_NAME]) visible = bool.Parse(categoryNode.Attributes[XML_VISIBLE_ATTRIBUTE_NAME].Value); CategoryItem newCategory = new CategoryItem(visible); newCategory.Name = categoryNode.GetAttribute(XML_NAME_ATTRIBUTE_NAME, ""); string captionID = categoryNode.GetAttribute(XML_CAPTIONID_ATTRIBUTE_NAME, ""); newCategory.Caption = (string)App.Current.FindResource(captionID); string typeName = categoryNode.GetAttribute(XML_TYPE_ATTRIBUTE_NAME, ""); newCategory.CategoryType = Type.GetType(typeName); // add new category to the parent newCategory.Parent = parent; parent.AddChild(newCategory); // process all other category childs foreach (XmlNode node in categoryNode.ChildNodes) { if (node.NodeType != XmlNodeType.Element) continue; // skip comments and other non element nodes if (node.Name.Equals(XML_CATEGORY_ELEMENT_NAME, StringComparison.OrdinalIgnoreCase)) _AddCategoryItem(newCategory as CategoryItem, node as XmlElement); else if (node.Name.Equals(XML_PAGE_ELEMENT_NAME, StringComparison.OrdinalIgnoreCase)) _AddPageItem(newCategory as CategoryItem, node as XmlElement); else throw new NotSupportedException(); } }