// Starts the process of creating SectionNode's from h1...h6 elements private void LoadFromXHTML(Uri fileUri) { XmlTextReader source = GetXmlReader(fileUri); source.WhitespaceHandling = WhitespaceHandling.Significant; bool foundHeadings = false; mCurrentSection = null; try { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.LocalName == "h1" || source.LocalName == "h2" || source.LocalName == "h3" || source.LocalName == "h4" || source.LocalName == "h5" || source.LocalName == "h6") { foundHeadings = true; Obi.SectionNode node = CreateSectionNode(source); if (node != null && node.Level < 6) { mOpenSectionNodes.Push(node); } mCurrentSection = node; } else if ((source.LocalName == "p" || source.LocalName == "span")) { string classAttr = source.GetAttribute("class"); if (classAttr == "page" || classAttr == "page-normal") { addPage(source, PageKind.Normal); } else if (classAttr == "page-front") { addPage(source, PageKind.Front); } else if (classAttr == "page-special") { addPage(source, PageKind.Special); } } } if (source.EOF) { break; } } } catch (Exception e) { source.Close(); throw e; } if (!foundHeadings) { throw new Exception(Localizer.Message("no_headings_found")); } }
private void ParseNccDocument(XmlNode node) { if (node.ChildNodes.Count == 0) { return; } foreach (XmlNode n in node.ChildNodes) { if (n.NodeType == XmlNodeType.Element) { if (n.LocalName == "h1" || n.LocalName == "h2" || n.LocalName == "h3" || n.LocalName == "h4" || n.LocalName == "h5" || n.LocalName == "h6") { //foundHeadings = true; Obi.SectionNode section = CreateSectionNode(n); if (section != null && section.Level < 6) { m_OpenSectionNodes.Push(section); } m_CurrentSection = section; m_SectionNodesToSmilReferenceMap.Add(section, GetSmilReferenceString(n)); } else if (n.LocalName == "p" || n.LocalName == "span") { string classAttr = n.Attributes.GetNamedItem("class").Value; if (classAttr == "phrase") { EmptyNode empty = m_Presentation.TreeNodeFactory.Create <EmptyNode>(); m_CurrentSection.AppendChild(empty); } else if (classAttr == "page" || classAttr == "page-normal") { addPage(n, PageKind.Normal); } else if (classAttr == "page-front") { addPage(n, PageKind.Front); } else if (classAttr == "page-special") { addPage(n, PageKind.Special); } } } ParseNccDocument(n); } }