protected override void OnCheck(string Name, System.Xml.XmlNode Node) { if (Name == "TEXTS") { foreach (System.Xml.XmlNode child in Node.ChildNodes) { if (child.Name.ToUpper() == "TEXT") { int index = -1; foreach (System.Xml.XmlAttribute attr in child.Attributes) { if (attr.Name.ToUpper() == "CODE") { index = GetInt(attr.InnerText); } } if (index > 0) { Format.Add(index, child.InnerText); } } } } base.OnCheck(Name, Node); }
public Exception(XElement node, string @namespace) { foreach (var format in node.Elements(XName.Get("Format", @namespace))) { Format.Add(format.Value); } }
// ReSharper restore InconsistentNaming #region Overrides of XmlObject public override void ReadXml(XmlReader reader) { reader.MoveToContent(); while (!reader.EOF) { if (reader.IsStartElement()) { switch (reader.LocalName) { case "Format": Format.Add(reader.ReadElementContentAsString()); break; case "DCPType": var tmp = new DCPType(); tmp.ReadXml(reader); DCPType.Add(tmp); break; default: reader.Skip(); break; } } else { reader.Read(); } } }
public static Format GetFormat(string format) { lock (lock_object) { if (!initialized) { Init(); } return(Format.Add(format)); } }
public OperationType(XElement node, string @namespace) { foreach (var formatNode in node.Elements(XName.Get("Format", @namespace))) { Format.Add(formatNode.Value); } foreach (var dcptype in node.Elements(XName.Get("DCPType", @namespace))) { DCPType.Add(new DCPType(dcptype, @namespace)); } if (Format.Count < 1) { throw WmsParsingException.ElementNotFound("Format"); } if (DCPType.Count < 1) { throw WmsParsingException.ElementNotFound("DCPType"); } }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.GetEntry(opfFilePath); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (Stream zipStream = _EpubFile.GetInputStream(zipEntry)) { using (MemoryStream memoryStream = new MemoryStream()) { byte[] buffer = new byte[4096]; // 4K is optimum StreamUtils.Copy(zipStream, memoryStream, buffer); memoryStream.Position = 0; contentOpf = XElement.Load(memoryStream); } } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null ? contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; UUID = contentOpf.Elements(xNamespace + "metadata").Elements() .FirstOrDefault(e => e.Name.LocalName == "identifier" && e.HasAttributes && e.Attribute("id") != null && e.Attribute("id").Value == uniqueIdentifier ).Value; foreach ( var metadataElement in contentOpf.Element(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase)); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (MemoryStream memoryStream = new MemoryStream()) { zipEntry.Extract(memoryStream); // Fix buggy "<?xml verison="1.1"?> // See http://stackoverflow.com/questions/912440/xdocument-cant-load-xml-with-version-1-1-in-c-sharp-linq byte[] b = memoryStream.ToArray(); for (int i = 0; i < 50; i++) { // Check for version="1.1" and replace if found if (b[i] == 0x76 && b[i + 1] == 0x65 && b[i + 2] == 0x72 && b[i + 3] == 0x73 && b[i + 4] == 0x69 && b[i + 5] == 0x6F && b[i + 6] == 0x6E && b[i + 7] == 0x3D && b[i + 8] == 0x22 && b[i + 9] == 0x31 && b[i + 10] == 0x2E && b[i + 11] == 0x31) { b[i + 11] = 0x30; } } using (MemoryStream fixedStream = new MemoryStream(b)) { contentOpf = XElement.Load(fixedStream); } b = null; } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; try { UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attributes("id").FirstOrDefault() != null && e.Attribute("id").Value == uniqueIdentifier).Value; } catch { } foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase)); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (MemoryStream memoryStream = new MemoryStream()) { zipEntry.Extract(memoryStream); memoryStream.Position = 0; contentOpf = XElement.Load(memoryStream); } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; try { UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attribute("id").Value == uniqueIdentifier).Value; } catch { } foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }