コード例 #1
0
ファイル: Serializer.cs プロジェクト: rocketeerbkw/DNA
 public static XmlDocument SerializeToXml(object data)
 {
     XmlDocument xml = new XmlDocument();
     using (StringWriterWithEncoding writer = new StringWriterWithEncoding(Encoding.UTF8))
     {
         XmlWriterSettings settings = new XmlWriterSettings();
         settings.Encoding = new UTF8Encoding(false);
         settings.Indent = true;
         settings.OmitXmlDeclaration = true;
         using (XmlWriter xWriter = XmlWriter.Create(writer, settings))
         {
             System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(data.GetType());
             x.Serialize(xWriter, data);
             xWriter.Flush();
             xml.LoadXml(Entities.GetEntities() + writer.ToString());
         }
     }
     return xml;
 }
コード例 #2
0
ファイル: StringUtils.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Takes a syndication feed and returns an Atom10 string
        /// </summary>
        /// <param name="feed">Syndication Feed</param>
        /// <returns>RSS formated string</returns>
        public static string SerializeToAtom10(SyndicationFeed feed)
        {
            using (StringWriterWithEncoding writer = new StringWriterWithEncoding(Encoding.UTF8))
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = new UTF8Encoding(false);
                //settings.Indent = true;

                using (XmlWriter xWriter = XmlWriter.Create(writer, settings))
                {
                    feed.SaveAsAtom10(xWriter);
                    xWriter.Flush();
                    return writer.ToString();
                }
            }
        }
コード例 #3
0
ファイル: DnaComponent.cs プロジェクト: rocketeerbkw/DNA
 /// <summary>
 /// Serialises the given object to an XmlDocument
 /// </summary>
 /// <param name="obj">The given object</param>
 /// <returns>An XmlDocument representing the serialised object</returns>
 protected XmlDocument SerialiseToXmlDoc(object obj)
 {
     XmlDocument xml = new XmlDocument();
     using (StringWriterWithEncoding writer = new StringWriterWithEncoding(Encoding.UTF8))
     {
         var ns = new XmlSerializerNamespaces();
         ns.Add("", "");
         XmlWriterSettings settings = new XmlWriterSettings();
         settings.Encoding = new UTF8Encoding(false);
         settings.Indent = true;
         settings.OmitXmlDeclaration = true;
         using (XmlWriter xWriter = XmlWriter.Create(writer, settings))
         {
             System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(obj.GetType());
             x.Serialize(xWriter, obj, ns);
             xWriter.Flush();
             xml.InnerXml = Entities.GetEntities() + writer.ToString();
         }
     }
     return xml;
 }