Пример #1
0
        internal static async Task <Spine> GetSpineAsync(this EBook ebook)
        {
            var spine = new Spine();

            IEnumerable <XElement> GetSpineItemNodes(string xml)
            {
                var doc  = XDocument.Parse(xml);
                var ns   = doc.Root.GetDefaultNamespace();
                var node = doc.Element(ns + "package").Element(ns + "spine");

                spine.Toc = node.Attribute("toc").Value;
                var itemNodes = node.Elements(ns + "itemref");

                return(itemNodes);
            }

            var contentFile = await ebook._rootFolder.GetFileFromPathAsync(ebook.ContentLocation);

            var contentXml = await FileIO.ReadTextAsync(contentFile);

            foreach (var itemNode in GetSpineItemNodes(contentXml).ToList())
            {
                spine.Add(new SpineItem
                {
                    IdRef = itemNode.Attribute("idref").Value
                });
            }

            return(spine);
        }
Пример #2
0
        public static Spine GetSpine(this EBook eBook)
        {
            var spine      = new Spine();
            var contentXml = File.ReadAllText(eBook.ContentLocation);
            var doc        = XDocument.Parse(contentXml);
            var ns         = doc.Root.GetDefaultNamespace();
            var spineNode  = doc.Element(ns + "package").Element(ns + "spine");

            spine.Toc = spineNode.Attribute("toc").Value;
            var itemNodes = spineNode.Elements(ns + "itemref").ToList();

            foreach (var node in itemNodes)
            {
                spine.Add(new SpineItem
                {
                    IdRef = node.Attribute("idref").Value
                });
            }

            return(spine);
        }