private static async Task <EpubNavigationHead> ReadNavigationHeadAsync(XmlReader reader) { EpubNavigationHead result = new EpubNavigationHead(); //"ncx:head" is our starting point bool headFound = await reader.ReadToFollowingAsync("head", "http://www.daisy.org/z3986/2005/ncx/"); if (!headFound) { throw new Exception("EPUB parsing error: head section not found in the .toc file."); } while (await reader.ReadAsync() && !(reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "head")) { if (reader.LocalName.ToLowerInvariant() == "meta") { EpubNavigationHeadMeta meta = new EpubNavigationHeadMeta(); while (reader.MoveToNextAttribute()) { switch (reader.LocalName.ToLowerInvariant()) { case "name": meta.Name = reader.Value; break; case "content": meta.Content = reader.Value; break; case "scheme": meta.Scheme = reader.Value; break; } } if (String.IsNullOrWhiteSpace(meta.Name)) { throw new Exception("Incorrect EPUB navigation meta: meta name is missing"); } if (meta.Content == null) { throw new Exception("Incorrect EPUB navigation meta: meta content is missing"); } result.Add(meta); } } return(result); }
private static EpubNavigationHead ReadNavigationHead(XElement headNode) { EpubNavigationHead result = new EpubNavigationHead(); foreach (XElement metaNode in headNode.Elements()) { if (string.Compare(metaNode.Name.LocalName, "meta", StringComparison.OrdinalIgnoreCase) == 0) { EpubNavigationHeadMeta meta = new EpubNavigationHeadMeta(); foreach (XAttribute metaNodeAttribute in metaNode.Attributes()) { string attributeValue = metaNodeAttribute.Value; switch (metaNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "name": meta.Name = attributeValue; break; case "content": meta.Content = attributeValue; break; case "scheme": meta.Scheme = attributeValue; break; } } if (string.IsNullOrWhiteSpace(meta.Name)) { throw new Exception("Incorrect EPUB navigation meta: meta name is missing."); } if (meta.Content == null) { throw new Exception("Incorrect EPUB navigation meta: meta content is missing."); } result.Add(meta); } } return(result); }