private static EpubNavigationPageTarget ReadNavigationPageTarget(XElement navigationPageTargetNode) { EpubNavigationPageTarget result = new EpubNavigationPageTarget(); foreach (XAttribute navigationPageTargetNodeAttribute in navigationPageTargetNode.Attributes()) { string attributeValue = navigationPageTargetNodeAttribute.Value; switch (navigationPageTargetNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "id": result.Id = attributeValue; break; case "value": result.Value = attributeValue; break; case "type": EpubNavigationPageTargetType type; if (!Enum.TryParse(attributeValue, out type)) { throw new Exception(String.Format("Incorrect EPUB navigation page target: {0} is incorrect value for page target type.", attributeValue)); } result.Type = type; break; case "class": result.Class = attributeValue; break; case "playOrder": result.PlayOrder = attributeValue; break; } } if (result.Type == default(EpubNavigationPageTargetType)) { throw new Exception("Incorrect EPUB navigation page target: page target type is missing."); } foreach (XElement navigationPageTargetChildNode in navigationPageTargetNode.Elements()) { switch (navigationPageTargetChildNode.Name.LocalName.ToLowerInvariant()) { case "navlabel": EpubNavigationLabel navigationLabel = ReadNavigationLabel(navigationPageTargetChildNode); result.NavigationLabels.Add(navigationLabel); break; case "content": EpubNavigationContent content = ReadNavigationContent(navigationPageTargetChildNode); result.Content = content; break; } } if (!result.NavigationLabels.Any()) { throw new Exception("Incorrect EPUB navigation page target: at least one navLabel element is required."); } return(result); }
private static EpubNavigationPageList ReadNavigationPageList(XElement navigationPageListNode) { EpubNavigationPageList result = new EpubNavigationPageList(); foreach (XElement pageTargetNode in navigationPageListNode.Elements()) { if (String.Compare(pageTargetNode.Name.LocalName, "pageTarget", StringComparison.OrdinalIgnoreCase) == 0) { EpubNavigationPageTarget pageTarget = ReadNavigationPageTarget(pageTargetNode); result.Add(pageTarget); } } return(result); }