void CreateShareazaXml(FictionBook book, ref ISXMLElement pXML) { ShareazaBook sbook = new ShareazaBook(book); Books sBooks = new Books(); sBooks.books[0] = sbook; MemoryStream ms = null; XmlWriter writer = null; string finalXml = String.Empty; try { XmlSerializer s = new XmlSerializer(typeof(Books)); s.UnknownNode += new XmlNodeEventHandler(OnUnknownNode); s.UnknownAttribute += new XmlAttributeEventHandler(OnUnknownAttribute); ms = new MemoryStream(); UTF8Encoding utf8 = new UTF8Encoding(false, false); writer = new XmlTextWriter(ms, utf8); XmlSerializerNamespaces xsn = new XmlSerializerNamespaces(); // Don't add any prefixes xsn.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance"); s.Serialize(writer, sBooks, xsn); // Start modifying the resulting XML XmlDocument doc = new XmlDocument(); ms.Position = 0; doc.Load(ms); XmlAttribute schema = doc.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); schema.Value = Books.URI; doc.DocumentElement.SetAttributeNode(schema); // Truncate the serialization result and overwrite it with our modified XML ms.SetLength(0); ms.Position = 0; writer = new XmlTextWriter(ms, utf8); doc.Save(writer); char[] buffer = Encoding.UTF8.GetChars(ms.ToArray()); finalXml = new string(buffer); } catch (Exception e) { Trace.WriteLine(e.Message); Exception inner = e.InnerException; while (inner != null) { Trace.WriteLine(inner.Message); inner = inner.InnerException; } } finally { if (writer != null) writer.Close(); if (ms != null) ms.Close(); } if (!String.IsNullOrEmpty(finalXml)) { Trace.WriteLine(finalXml); ISXMLElement newXML = pXML.FromString(finalXml); if (newXML != null) { pXML.Elements.Attach(newXML); } } }
public EnvyBook(FictionBook fb) { Trace.Assert(fb != null); if (fb.description == null) { return; } CultureInfo ciDefault = Thread.CurrentThread.CurrentCulture; CultureInfo ciDoc = ciDefault; if (fb.description.titleinfo == null) { if (fb.description.custominfo != null) { // Title in english ??? // custominfo and titleinfo should have a common interface then... // this.title = fb.description.custominfo... } } else { this.title = fb.description.titleinfo.booktitle.Value; this.author = GetAuthors(fb.description.titleinfo.author); try { string sLang = fb.description.titleinfo.lang; if (!String.IsNullOrEmpty(sLang)) { // returns neutral culture!!! Beware when formatting ciDoc = CultureInfo.GetCultureInfoByIetfLanguageTag(sLang); this.language = ciDoc.EnglishName; // guess it ciDoc = CultureInfo.CreateSpecificCulture(sLang + "-" + sLang); } } catch { } if (fb.description.titleinfo.genre != null && fb.description.titleinfo.genre.Length > 0) { this._genre = GenreMap.GetPeerGenre(fb.description.titleinfo.genre[0].Value); } // this.year = fb.description.titleinfo.date.value.Year; if (fb.description.titleinfo.keywords != null) { this.keywords = fb.description.titleinfo.keywords.Value; } } if (fb.description.publishinfo != null) { this.publisher = fb.description.publishinfo.publisher.Value; this.year = fb.description.publishinfo.year; if (fb.description.publishinfo.isbn != null) { string sISBN = fb.description.publishinfo.isbn.Value; if (!String.IsNullOrEmpty(sISBN)) { Int64 isbn; if (Int64.TryParse(sISBN, out isbn)) { this.ISBN = isbn; } else { sISBN = sISBN.Replace(@"-", String.Empty); if (Int64.TryParse(sISBN, out isbn)) { this.ISBN = isbn; } } } } } if (fb.description.documentinfo != null) { this.distributer = GetAuthors(fb.description.documentinfo.author); this.releaseDate = GetDate(ciDoc, fb.description.documentinfo.date); this.edition = fb.description.documentinfo.version.ToString(); } this.back = BackType.Digital; this.format = FormatType.FictionBook; }
public ShareazaBook(FictionBook fb) { Trace.Assert(fb != null); if (fb.description == null) return; CultureInfo ciDefault = Thread.CurrentThread.CurrentCulture; CultureInfo ciDoc = ciDefault; if (fb.description.titleinfo == null) { if (fb.description.custominfo != null) { // Title in english ??? // custominfo and titleinfo should have a common interface then... // this.title = fb.description.custominfo... } } else { this.title = fb.description.titleinfo.booktitle.Value; this.author = GetAuthors(fb.description.titleinfo.author); try { string sLang = fb.description.titleinfo.lang; if (!String.IsNullOrEmpty(sLang)) { // returns neutral culture!!! Beware when formatting ciDoc = CultureInfo.GetCultureInfoByIetfLanguageTag(sLang); this.language = ciDoc.EnglishName; // guess it ciDoc = CultureInfo.CreateSpecificCulture(sLang + "-" + sLang); } } catch { } if (fb.description.titleinfo.genre != null && fb.description.titleinfo.genre.Length > 0) { this._genre = GenreMap.GetRazaGenre(fb.description.titleinfo.genre[0].Value); } // this.year = fb.description.titleinfo.date.value.Year; if (fb.description.titleinfo.keywords != null) this.keywords = fb.description.titleinfo.keywords.Value; this.description = GetDescription(fb.description.titleinfo.annotation); } if (fb.description.publishinfo != null) { this.publisher = fb.description.publishinfo.publisher.Value; this.year = fb.description.publishinfo.year; if (fb.description.publishinfo.isbn != null) { string sISBN = fb.description.publishinfo.isbn.Value; if (!String.IsNullOrEmpty(sISBN)) { Int64 isbn; if (Int64.TryParse(sISBN, out isbn)) { this.ISBN = isbn; } else { sISBN = sISBN.Replace(@"-", String.Empty); if (Int64.TryParse(sISBN, out isbn)) { this.ISBN = isbn; } } } } } if (fb.description.documentinfo != null) { this.distributer = GetAuthors(fb.description.documentinfo.author); this.releaseDate = GetDate(ciDoc, fb.description.documentinfo.date); this.edition = fb.description.documentinfo.version.ToString(); } this.back = BackType.Digital; this.format = FormatType.FictionBook; }