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); }
private static EpubSpine ReadSpine(XElement spineNode) { var result = new EpubSpine(); var tocAttribute = spineNode.Attribute("toc"); if (string.IsNullOrWhiteSpace(tocAttribute?.Value)) { throw new Exception("Incorrect EPUB spine: TOC is missing"); } result.Toc = tocAttribute?.Value; foreach (var spineItemNode in spineNode.Elements()) { if (string.Compare(spineItemNode.Name.LocalName, "itemref", StringComparison.OrdinalIgnoreCase) is 0) { var spineItemRef = new EpubSpineItemRef(); var idRefAttribute = spineItemNode.Attribute("idref"); if (idRefAttribute is null || string.IsNullOrWhiteSpace(idRefAttribute.Value)) { throw new Exception("Incorrect EPUB spine: item ID ref is missing"); } spineItemRef.IdRef = idRefAttribute.Value; var linearAttribute = spineItemNode.Attribute("linear"); spineItemRef.IsLinear = linearAttribute is null || string.Compare(linearAttribute.Value, "no", StringComparison.OrdinalIgnoreCase) != 0; result.Add(spineItemRef); } } return(result); }
private static EpubSpine ReadSpine(XElement spineNode, EpubVersion epubVersion) { EpubSpine result = new EpubSpine(); foreach (XAttribute spineNodeAttribute in spineNode.Attributes()) { string attributeValue = spineNodeAttribute.Value; switch (spineNodeAttribute.GetLowerCaseLocalName()) { case "id": result.Id = attributeValue; break; case "page-progression-direction": result.PageProgressionDirection = PageProgressionDirectionParser.Parse(attributeValue); break; case "toc": result.Toc = attributeValue; break; } } if (epubVersion == EpubVersion.EPUB_2 && String.IsNullOrWhiteSpace(result.Toc)) { throw new Exception("Incorrect EPUB spine: TOC is missing"); } foreach (XElement spineItemNode in spineNode.Elements()) { if (spineItemNode.CompareNameTo("itemref")) { EpubSpineItemRef spineItemRef = new EpubSpineItemRef(); foreach (XAttribute spineItemNodeAttribute in spineItemNode.Attributes()) { string attributeValue = spineItemNodeAttribute.Value; switch (spineItemNodeAttribute.GetLowerCaseLocalName()) { case "id": spineItemRef.Id = attributeValue; break; case "idref": spineItemRef.IdRef = attributeValue; break; case "properties": spineItemRef.Properties = SpinePropertyParser.ParsePropertyList(attributeValue); break; } } if (String.IsNullOrWhiteSpace(spineItemRef.IdRef)) { throw new Exception("Incorrect EPUB spine: item ID ref is missing"); } XAttribute linearAttribute = spineItemNode.Attribute("linear"); spineItemRef.IsLinear = linearAttribute == null || !linearAttribute.CompareValueTo("no"); result.Add(spineItemRef); } } return(result); }
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); }
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; }
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; }