private void CreateStructure(List <int> levelsList, List <string> sectionNamesList, List <int> pagesPerSection) { List <ObiNode> listOfSectionNodes = new List <ObiNode>(); listOfSectionNodes.Add((ObiNode)m_Presentation.RootNode); int pageNumber = 0; SectionNode currentSection = null; Console.WriteLine("level list count" + levelsList.Count); for (int i = 0; i < levelsList.Count; i++) { SectionNode section = m_Presentation.CreateSectionNode(); section.Label = sectionNamesList[i].Trim(); Console.WriteLine("section " + section.Label + ", level: " + levelsList[i]); if (currentSection == null) { m_Presentation.RootNode.AppendChild(section); } else { // iterate back in list of sections to find the parent for (int j = listOfSectionNodes.Count - 1; j >= 0; j--) { ObiNode iterationSection = listOfSectionNodes[j]; if (iterationSection.Level < levelsList[i]) { iterationSection.AppendChild(section); break; } } } currentSection = section; listOfSectionNodes.Add(section); if (pagesPerSection[i] > 0) { for (int j = 0; j < pagesPerSection[i]; j++) { EmptyNode pageNode = m_Presentation.TreeNodeFactory.Create <EmptyNode>(); ++pageNumber; pageNode.PageNumber = new PageNumber(pageNumber, PageKind.Normal); section.AppendChild(pageNode); Console.WriteLine("page : " + pageNode.PageNumber.ToString()); } } } }
private void ParseTOC(XmlNode xNode, ObiNode parentNode) { if (xNode.Name == "li") { SectionNode section = m_Presentation.CreateSectionNode(); parentNode.AppendChild(section); parentNode = section; } else if (xNode is XmlText) { if (parentNode is SectionNode) { SectionNode parentSection = (SectionNode)parentNode; parentSection.Label = xNode.InnerText; } } else if (xNode.Name == "a") { if (parentNode is SectionNode) { XmlNode hrefNode = xNode.Attributes.GetNamedItem("href"); string headingReference = hrefNode.Value; if (!m_XmlIdToSectionNodeMap.ContainsKey(headingReference)) { m_XmlIdToSectionNodeMap.Add(headingReference, (SectionNode)parentNode); } } } if (xNode.ChildNodes.Count == 0) { return; } foreach (XmlNode n in xNode.ChildNodes) { ParseTOC(n, parentNode); } }