void ReadMeta3() { XFragment f = XFragment.FindFragment("metadata", OPF.text); List <MetaRecord> primary = new List <MetaRecord>(); foreach (var e in f.root.childs) { switch (e.tag.tagname) { case "dc:language": case "dc:identifier": { var t = new MetaRecord(e); primary.Add(t); } break; case "meta": { string name = e.tag.GetAttribute("name"); if (name != "") { var t = new MetaRecord(); t.name = name; t.value = e.tag.GetAttribute("content"); meta.Add(t); continue; } string refines = e.tag.GetAttribute("refines"); if (refines != "") { if (refines.StartsWith("#") && refines.Length > 1) { string id = refines.Substring(1); var t = new MetaRecord(e); t.name = e.tag.GetAttribute("property"); t.AddIfExist(e, "scheme"); foreach (var r in primary) { //要是refine在primary前面我可不管…… if (r.id == id) { r.refines.Add(t); break; } } continue; } } string property = e.tag.GetAttribute("property"); if (property != "") { var t = new MetaRecord(e); t.name = property; meta.Add(t); continue; } } break; default: { var t = new MetaRecord(e); t.AddIfExist(e, "xml:lang"); t.AddIfExist(e, "dir"); primary.Add(t); } break; } } foreach (var a in primary) { switch (a.name) { case "dc:title": dc_titles.Add(a); break; case "dc:creator": dc_creators.Add(a); break; case "dc:identifier": dc_identifier.Add(a); break; case "dc:language": dc_language.Add(a); break; default: others.Add(a); break; } } foreach (var a in dc_identifier) { if (idref == a.id) { uniqueIdentifier = a; break; } } foreach (var a in manifest) { switch (a.Value.properties) { case "nav": _toc = a.Value; break; case "cover-image": cover_img = a.Value.href; break; } } if (_toc == null) { _toc = spine.toc; } //check //if (dc_titles.Count == 0 || dc_identifier.Count == 0 || dc_language.Count == 0) { throw new EpubErrorException("Lack of some metadata."); } }
void ReadMeta3() { var f = packageDocument.GetElementsByTagName("metadata")[0] as XmlElement; List <MetaRecord> primary = new List <MetaRecord>(); foreach (XmlNode node in f.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; } var e = (XmlElement)node; string n = e.Name; switch (n) { case "dc:language": case "dc:identifier": { var t = new MetaRecord(e); primary.Add(t); } break; case "meta": { string name = e.GetAttribute("name"); if (name != "") { var t = new MetaRecord(); t.name = name; t.value = e.GetAttribute("content"); meta.Add(t); continue; } string refines = e.GetAttribute("refines"); if (refines != "") { if (refines.StartsWith("#") && refines.Length > 1) { string id = refines.Substring(1); var t = new MetaRecord(e); t.name = e.GetAttribute("property"); t.AddIfExist(e, "scheme"); foreach (var r in primary) { //要是refine在primary前面我可不管…… if (r.id == id) { r.refines.Add(t); break; } } continue; } } string property = e.GetAttribute("property"); if (property != "") { var t = new MetaRecord(e); t.name = property; meta.Add(t); continue; } } break; default: { var t = new MetaRecord(e); t.AddIfExist(e, "xml:lang"); t.AddIfExist(e, "dir"); primary.Add(t); } break; } } foreach (var a in primary) { switch (a.name) { case "dc:title": titleRecords.Add(a); break; case "dc:creator": creatorRecords.Add(a); break; case "dc:identifier": identifierRecords.Add(a); break; case "dc:language": languageRecords.Add(a); break; default: otherRecords.Add(a); break; } } foreach (var a in identifierRecords) { if (idref == a.id) { uniqueIdentifier = a; break; } } foreach (var a in manifest) { switch (a.Value.properties) { case "nav": _toc = a.Value; break; case "cover-image": coverImage = a.Value; break; } } if (_toc == null) { _toc = spine.toc; } //check //if (dc_titles.Count == 0 || dc_identifier.Count == 0 || dc_language.Count == 0) { throw new EpubErrorException("Lack of some metadata."); } }
void ReadMeta2() { XFragment f = XFragment.FindFragment("metadata", OPF.text); foreach (var e in f.root.childs) { switch (e.tag.tagname) { case "dc:title": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:file-as"); dc_titles.Add(t); } break; case "dc:creator": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:file-as"); t.AddIfExist(e, "opf:role"); dc_creators.Add(t); } break; case "dc:language": { var t = new MetaRecord(e); dc_language.Add(t); } break; case "dc:identifier": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:scheme"); dc_identifier.Add(t); } break; case "dc:contributor": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:file-as"); t.AddIfExist(e, "opf:role"); others.Add(t); } break; case "dc:date": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:event"); others.Add(t); } break; case "meta": { var t = new MetaRecord(); t.name = e.tag.GetAttribute("name"); t.value = e.tag.GetAttribute("content"); meta.Add(t); } break; default: { var t = new MetaRecord(e); others.Add(t); } break; } } foreach (var a in meta) { if (a.name == "cover") { string id = a.value; if (manifest.ContainsKey(id)) { cover_img = manifest[id].href; } break; } } _toc = spine.toc; }
void ReadMeta2() { var f = packageDocument.GetElementsByTagName("metadata")[0] as XmlElement; foreach (XmlNode node in f.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; } var e = (XmlElement)node; string n = e.Name; switch (n) { case "dc:title": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:file-as"); titleRecords.Add(t); } break; case "dc:creator": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:file-as"); t.AddIfExist(e, "opf:role"); creatorRecords.Add(t); } break; case "dc:language": { var t = new MetaRecord(e); languageRecords.Add(t); } break; case "dc:identifier": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:scheme"); identifierRecords.Add(t); } break; case "dc:contributor": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:file-as"); t.AddIfExist(e, "opf:role"); otherRecords.Add(t); } break; case "dc:date": { var t = new MetaRecord(e); t.AddIfExist(e, "opf:event"); otherRecords.Add(t); } break; case "meta": { var t = new MetaRecord(); t.name = e.GetAttribute("name"); t.value = e.GetAttribute("content"); meta.Add(t); } break; default: { var t = new MetaRecord(e); otherRecords.Add(t); } break; } } foreach (var a in meta) { if (a.name == "cover") { string id = a.value; if (manifest.ContainsKey(id)) { coverImage = manifest[id]; } break; } } foreach (var a in identifierRecords) { if (idref == a.id) { uniqueIdentifier = a; break; } } _toc = spine.toc; }