Ejemplo n.º 1
0
        private static async Task<EpubSpine> ReadSpineAsync(XmlReader reader)
        {
            EpubSpine result = new EpubSpine();
            bool spineFound = await reader.ReadToFollowingAsync("spine", "http://www.idpf.org/2007/opf");
            if (!spineFound)
                throw new Exception("EPUB parsing error: spine declarations not found in the package.");

            if (String.IsNullOrWhiteSpace(reader.GetAttribute("toc")))
                throw new Exception("Incorrect EPUB spine: TOC attribute is missing or empty");
            result.Toc = reader.GetAttribute("toc");

            while (await reader.ReadAsync() && !(reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "spine"))
            {
                if (reader.LocalName.ToLowerInvariant() == "itemref")
                {
                    EpubSpineItemRef spineItemRef = new EpubSpineItemRef();
                    spineItemRef.IsLinear = true;
                    while (reader.MoveToNextAttribute())
                    {
                        switch (reader.LocalName.ToLowerInvariant())
                        {
                            case "idref":
                                spineItemRef.IdRef = reader.Value;
                                break;
                            case "linear":
                                if (reader.Value.ToLowerInvariant() == "no")
                                {
                                    spineItemRef.IsLinear = false;
                                }
                                break;
                        }
                    }
                    result.Add(spineItemRef);
                }
            }
            return result;
        }
Ejemplo n.º 2
0
 private static EpubSpine ReadSpine(XmlNode spineNode)
 {
     EpubSpine result = new EpubSpine();
     XmlAttribute tocAttribute = spineNode.Attributes["toc"];
     if (tocAttribute == null || String.IsNullOrWhiteSpace(tocAttribute.Value))
         throw new Exception("Incorrect EPUB spine: TOC is missing");
     result.Toc = tocAttribute.Value;
     foreach (XmlNode spineItemNode in spineNode.ChildNodes)
         if (String.Compare(spineItemNode.LocalName, "itemref", StringComparison.OrdinalIgnoreCase) == 0)
         {
             EpubSpineItemRef spineItemRef = new EpubSpineItemRef();
             XmlAttribute idRefAttribute = spineItemNode.Attributes["idref"];
             if (idRefAttribute == null || String.IsNullOrWhiteSpace(idRefAttribute.Value))
                 throw new Exception("Incorrect EPUB spine: item ID ref is missing");
             spineItemRef.IdRef = idRefAttribute.Value;
             XmlAttribute linearAttribute = spineItemNode.Attributes["linear"];
             spineItemRef.IsLinear = linearAttribute == null || String.Compare(linearAttribute.Value, "no", StringComparison.OrdinalIgnoreCase) != 0;
             result.Add(spineItemRef);
         }
     return result;
 }