private SiteMapNode ReadSitemapFromXml(string sitemapUrl) { SiteMapNode rootNode = null; NodeDictionary = new Dictionary <string, SiteMapNode>(); // ideally, we would need a SiteMapSource property which is the file to read from, and a SiteMapFile property which is the file to write to // note: these two cannot be the same because the links in the sitemap are parsed, so the output is different from the input! //string sitemap = PageFactory.FindPageContent(sitemapUrl); string sitemap; if (!PageFactory.TryFindPageContent(sitemapUrl, out sitemap)) { sitemap = emptySiteMapString(); } XDocument xDoc = XDocument.Parse(sitemap); XElement siteMapRoot = xDoc.Element("siteMap"); try { rootNode = new TridionSiteMapNode(this, String.Empty, String.Empty, String.Empty, String.Empty, new ArrayList(), new NameValueCollection(), new NameValueCollection(), String.Empty); AddNode(rootNode); //Fill down the hierarchy. AddChildren(rootNode, siteMapRoot.Elements(), 1); } catch (Exception e) { Exception e2 = e; } return(rootNode); }
private void AddChildren(SiteMapNode rootNode, IEnumerable <XElement> siteMapNodes, int currentLevel) { foreach (var element in siteMapNodes) { TridionSiteMapNode childNode; var attributes = new NameValueCollection(); foreach (var a in element.Attributes()) { attributes.Add(a.Name.ToString(), a.Value); } childNode = new TridionSiteMapNode(this, element.Attribute("id").Value, //key null, //url element.Attribute("title").Value, //title element.Attribute("description").Value, //description null, //roles attributes, //attributes null, //explicitresourceKeys null) { Uri = element.Attribute("url").Value, Level = currentLevel }; // implicitresourceKey NodeDictionary.Add(childNode.Key, childNode); //Use the SiteMapNode AddNode method to add the SiteMapNode to the ChildNodes collection AddNode(childNode, rootNode); // Check for children in this node. AddChildren(childNode, element.Elements(), currentLevel + 1); } }