private static void PullNodeFromEntity(string outernode, string innernodes, XmlElement entNode, DirectoryStack dir) { var tdir = outernode; foreach (var xCol in entNode.GetElementsByTagName(outernode).Cast <XmlElement>()) { var nodes = xCol.GetElementsByTagName(innernodes).Cast <XmlElement>(); if (outernode == "forms") { tdir = outernode + "_" + xCol.GetAttribute("type"); } dir.Push(tdir); Directory.CreateDirectory(dir); while (nodes.Any()) { var e = nodes.ElementAt(0); var query = (e.GetElementsByTagName("LocalizedName")[0] as XmlElement).GetAttribute("description"); query = new string(query.Where(c => !Path.GetInvalidPathChars().Contains(c) && !"?:\\/".Contains(c)).ToArray()); WriteElement(e, query, dir + "/" + query + ".xml"); var xlink = entNode.OwnerDocument.CreateElement(innernodes + "Link"); xlink.InnerText = dir + "/" + query + ".xml"; xCol.RemoveChild(e); xCol.AppendChild(xlink); } dir.Pop(); } }
private static void ExtractEntity(XmlElement entNode) { var dir = new DirectoryStack("entities"); var name = entNode["Name"].InnerText; dir.Push(name); Directory.CreateDirectory(dir); var xCol = (XmlElement)entNode.GetElementsByTagName("attributes")[0]; if (xCol != null) { var nodes = xCol.GetElementsByTagName("attribute").Cast <XmlElement>(); dir.Push("attributes"); Directory.CreateDirectory(dir); while (nodes.Any()) { var e = nodes.ElementAt(0); var attr = e.GetAttribute("PhysicalName"); WriteElement(e, attr, dir + "/" + attr + ".xml"); var xlink = entNode.OwnerDocument.CreateElement("AttributeLink"); xlink.InnerText = dir + "/" + attr + ".xml"; xCol.RemoveChild(e); xCol.AppendChild(xlink); } dir.Pop(); } PullNodeFromEntity("forms", "systemform", entNode, dir); PullNodeFromEntity("savedqueries", "savedquery", entNode, dir); PullNodeFromEntity("Visualizations", "visualization", entNode, dir); }