private List <XmlTree> getItems(XElement root) { var items = new List <XmlTree>(); foreach (var item in root.Elements()) { var tree = new XmlTree(); tree.Name = item.Name.LocalName; tree.Items = getItems(item); tree.Value = item.Value; items.Add(tree); } return(items); }
private string ParseXml(string xml) { var result = new XmlTree(); var root = XElement.Parse(xml); result.Name = root.Name.LocalName; result.Items = getItems(root); result.Value = root.Value; string res = ""; if (!result.Items.Any()) { res = "<div class=\"value-row\"><div class=\"tag\"><p>" + result.Name + "</p></div><div class=\"value\"><p>" + getValue(result.Value) + "</p></div></div>"; } else { res = "<div class=\"tree-row\"><span class=\"opened\"></span><" + result.Name + "><div class=\"inner\">" + getHtml(result.Items, 0) + "</div></" + result.Name + "></div>"; } return(res); }