private static EpubNavigationHead ReadNavigationHead(XmlNode headNode) { EpubNavigationHead result = new EpubNavigationHead(); foreach (XmlNode metaNode in headNode.ChildNodes) if (String.Compare(metaNode.LocalName, "meta", StringComparison.OrdinalIgnoreCase) == 0) { EpubNavigationHeadMeta meta = new EpubNavigationHeadMeta(); foreach (XmlAttribute metaNodeAttribute in metaNode.Attributes) { string attributeValue = metaNodeAttribute.Value; switch (metaNodeAttribute.Name.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; }
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; }