private static Epub2NcxNavigationPoint ReadNavigationPoint(XElement navigationPointNode) { Epub2NcxNavigationPoint result = new Epub2NcxNavigationPoint(); foreach (XAttribute navigationPointNodeAttribute in navigationPointNode.Attributes()) { string attributeValue = navigationPointNodeAttribute.Value; switch (navigationPointNodeAttribute.GetLowerCaseLocalName()) { case "id": result.Id = attributeValue; break; case "class": result.Class = attributeValue; break; case "playorder": result.PlayOrder = attributeValue; break; } } if (String.IsNullOrWhiteSpace(result.Id)) { throw new Exception("Incorrect EPUB navigation point: point ID is missing."); } result.NavigationLabels = new List <Epub2NcxNavigationLabel>(); result.ChildNavigationPoints = new List <Epub2NcxNavigationPoint>(); foreach (XElement navigationPointChildNode in navigationPointNode.Elements()) { switch (navigationPointChildNode.GetLowerCaseLocalName()) { case "navlabel": Epub2NcxNavigationLabel navigationLabel = ReadNavigationLabel(navigationPointChildNode); result.NavigationLabels.Add(navigationLabel); break; case "content": Epub2NcxContent content = ReadNavigationContent(navigationPointChildNode); result.Content = content; break; case "navpoint": Epub2NcxNavigationPoint childNavigationPoint = ReadNavigationPoint(navigationPointChildNode); result.ChildNavigationPoints.Add(childNavigationPoint); break; } } if (!result.NavigationLabels.Any()) { throw new Exception($"EPUB parsing error: navigation point {result.Id} should contain at least one navigation label."); } if (result.Content == null) { throw new Exception($"EPUB parsing error: navigation point {result.Id} should contain content."); } return(result); }
private static Epub2NcxNavigationMap ReadNavigationMap(XElement navigationMapNode) { Epub2NcxNavigationMap result = new Epub2NcxNavigationMap(); foreach (XElement navigationPointNode in navigationMapNode.Elements()) { if (navigationPointNode.CompareNameTo("navPoint")) { Epub2NcxNavigationPoint navigationPoint = ReadNavigationPoint(navigationPointNode); result.Add(navigationPoint); } } return(result); }