How do I specify Serialize encoding

Sep 21, 2010 at 3:30 PM

My XSD schema specifies <?xml version="1.0" encoding="utf-8"?> but when I serialize my class the XML string does not specify the the encoding. How do I get it to include the encoding type?

Thanks

 

Coordinator
Sep 21, 2010 at 8:11 PM

Hi,

I have to integrate the encoding as an option.
For the moment the only way is to change the Serialize method like this :

        /// <summary>
        /// Serializes current Actor object into an XML document
        /// </summary>
        /// <returns>string XML value</returns>
        public virtual string Serialize()
        {
            System.IO.StreamReader streamReader = null;
            System.IO.MemoryStream memoryStream = null;
            try
            {
                memoryStream = new System.IO.MemoryStream();
                XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
                Serializer.Serialize(xmlTextWriter, this);
                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                streamReader = new System.IO.StreamReader(memoryStream);
                return streamReader.ReadToEnd();
            }
            finally
            {
                if ((streamReader != null))
                {
                    streamReader.Dispose();
                }
                if ((memoryStream != null))
                {
                    memoryStream.Dispose();
                }
            }
        }

Pascal.

Sep 23, 2010 at 11:57 AM
Thank you for your help.

--
Regards
Avraham Tuvy