private string FindImageInXml(string path) { XDocument coverFile = _zip.GetFileStream(_oebps + path).GetXmlDocument(); XElement coverRoot = coverFile.Root; if (coverRoot == null) { return(null); } XElement image = coverRoot.DescendantNodes().OfType <XElement>().FirstOrDefault(n => n.Name.LocalName == "image"); if (image != null) { XAttribute href = image.Attributes().FirstOrDefault(a => a.Name.LocalName == "href"); if (href != null) { return(href.Value); } } XElement img = coverRoot.DescendantNodes().OfType <XElement>().FirstOrDefault(n => n.Name.LocalName == "img"); if (img != null) { XAttribute src = img.Attributes().FirstOrDefault(a => a.Name.LocalName == "src"); if (src != null) { return(src.Value); } } return(null); }
public override void BuildChapters() { Chapters.Clear(); string ncxPath = GetNcxPath(); if (!string.IsNullOrEmpty(ncxPath)) { string path = _opfPath + ncxPath; XDocument xmlDocument = _zip.GetFileStream((_opfPath) + ncxPath, true, true).GetXmlDocument(true); XNamespace ns = XNamespace.Get("http://www.daisy.org/z3986/2005/ncx/"); XElement root = xmlDocument.Root; if (root != null) { XElement navMap = root.Element(ns + "navMap"); ParseItems(navMap, 0, ns, path); } } }
private IEnumerable <EpubSpineItem> GetSpineItems() { XElement manifest = _opfRoot.Element((_opfns + "manifest")); return(from itemId in GetItemIDs() select GetPath(itemId, manifest) into path where !string.IsNullOrEmpty(path) let spineStream = _zip.GetFileStream(_opfPath + path, false, true) where spineStream != null select new EpubSpineItem { Stream = spineStream, Path = path }); }
public EpubSummaryParser(Stream source) { _zip = ZipContainer.Unzip(source); XDocument xmlDocument = _zip.GetFileStream("META-INF/container.xml").GetXmlDocument(); XElement root = xmlDocument.Root; if (root == null) { throw new DataException(InvalidEpubMetaInfo); } XAttribute attribute = root.Attribute("xmlns"); XNamespace xmlns = (attribute != null) ? XNamespace.Get(attribute.Value) : XNamespace.None; XAttribute fullPath = xmlDocument.Descendants(xmlns + "rootfile").First().Attribute("full-path"); if (fullPath == null) { throw new DataException(InvalidEpubMetaInfo); } string path = fullPath.Value; _opfPath = path; _opf = _zip.GetFileStream(path).GetXmlDocument(); _opfRoot = _opf.Root; if (_opfRoot == null) { throw new DataException(InvalidEpubMetaInfo); } _oebps = GetPath(path); _opfns = XNamespace.Get("http://www.idpf.org/2007/opf"); _opfdc = XNamespace.Get("http://purl.org/dc/elements/1.1/"); _coverHelper = new EpubCoverHelper(_zip, _opfns, _opfRoot, _oebps); }