Skip to main content
deleted 46 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Object to xml-to-XML string implementation

I have recently implemented a code to accomplish Object to stringObject-to-String. Can you guys suggest any pros and cons with regard to the code. Any much generalized code would be welcome.?

public static string ObjectToXml(object obj)
{
    var oXmlSerializer = new XmlSerializer(obj.GetType());
    var oStringWriter = new StringWriter();
    var oXmlSerializerNamespaces = new XmlSerializerNamespaces();
    oXmlSerializerNamespaces.Add(string.Empty,string.Empty);
    var oXmlWriterSettings = new XmlWriterSettings
    {
        Indent = true,
        OmitXmlDeclaration = false,
        Encoding = Encoding.GetEncoding("ISO-8859-1")
    };

    var oXmlWriter = XmlWriter.Create(oStringWriter,oXmlWriterSettings);
    oXmlSerializer.Serialize(oXmlWriter, obj, oXmlSerializerNamespaces);
    oXmlWriter.Close();
    return oStringWriter.ToString();
}

Object to xml string implementation

I have recently implemented a code to accomplish Object to string. Can you guys suggest any pros and cons with regard to the code. Any much generalized code would be welcome.

public static string ObjectToXml(object obj)
{
    var oXmlSerializer = new XmlSerializer(obj.GetType());
    var oStringWriter = new StringWriter();
    var oXmlSerializerNamespaces = new XmlSerializerNamespaces();
    oXmlSerializerNamespaces.Add(string.Empty,string.Empty);
    var oXmlWriterSettings = new XmlWriterSettings
    {
        Indent = true,
        OmitXmlDeclaration = false,
        Encoding = Encoding.GetEncoding("ISO-8859-1")
    };

    var oXmlWriter = XmlWriter.Create(oStringWriter,oXmlWriterSettings);
    oXmlSerializer.Serialize(oXmlWriter, obj, oXmlSerializerNamespaces);
    oXmlWriter.Close();
    return oStringWriter.ToString();
}

Object-to-XML string implementation

I have recently implemented a code to accomplish Object-to-String. Can you suggest any pros and cons with regard to the code?

public static string ObjectToXml(object obj)
{
    var oXmlSerializer = new XmlSerializer(obj.GetType());
    var oStringWriter = new StringWriter();
    var oXmlSerializerNamespaces = new XmlSerializerNamespaces();
    oXmlSerializerNamespaces.Add(string.Empty,string.Empty);
    var oXmlWriterSettings = new XmlWriterSettings
    {
        Indent = true,
        OmitXmlDeclaration = false,
        Encoding = Encoding.GetEncoding("ISO-8859-1")
    };

    var oXmlWriter = XmlWriter.Create(oStringWriter,oXmlWriterSettings);
    oXmlSerializer.Serialize(oXmlWriter, obj, oXmlSerializerNamespaces);
    oXmlWriter.Close();
    return oStringWriter.ToString();
}
deleted 128 characters in body
Source Link

I have recently implemented a code to accomplish Object to string. Can you guys suggest any pros and cons with regard to the code. Any much generalized code would be welcome.

public static string ObjectToXml(object obj)
        {
            var oXmlSerializer = new XmlSerializer(obj.GetType());
            var oStringWriter = new StringWriter();
            var oXmlSerializerNamespaces = new XmlSerializerNamespaces();
            oXmlSerializerNamespaces.Add(string.Empty,string.Empty);
            var oXmlWriterSettings = new XmlWriterSettings
            {
                Indent = true,
                OmitXmlDeclaration = false,
                Encoding = Encoding.GetEncoding("ISO-8859-1")
            };

            var oXmlWriter = XmlWriter.Create(oStringWriter,oXmlWriterSettings);
            oXmlSerializer.Serialize(oXmlWriter, obj, oXmlSerializerNamespaces);
            oXmlWriter.Close();
            return oStringWriter.ToString();
        }

I have recently implemented a code to accomplish Object to string. Can you guys suggest any pros and cons with regard to the code. Any much generalized code would be welcome.

public static string ObjectToXml(object obj)
        {
            var oXmlSerializer = new XmlSerializer(obj.GetType());
            var oStringWriter = new StringWriter();
            var oXmlSerializerNamespaces = new XmlSerializerNamespaces();
            oXmlSerializerNamespaces.Add(string.Empty,string.Empty);
            var oXmlWriterSettings = new XmlWriterSettings
            {
                Indent = true,
                OmitXmlDeclaration = false,
                Encoding = Encoding.GetEncoding("ISO-8859-1")
            };

            var oXmlWriter = XmlWriter.Create(oStringWriter,oXmlWriterSettings);
            oXmlSerializer.Serialize(oXmlWriter, obj, oXmlSerializerNamespaces);
            oXmlWriter.Close();
            return oStringWriter.ToString();
        }

I have recently implemented a code to accomplish Object to string. Can you guys suggest any pros and cons with regard to the code. Any much generalized code would be welcome.

public static string ObjectToXml(object obj)
{
    var oXmlSerializer = new XmlSerializer(obj.GetType());
    var oStringWriter = new StringWriter();
    var oXmlSerializerNamespaces = new XmlSerializerNamespaces();
    oXmlSerializerNamespaces.Add(string.Empty,string.Empty);
    var oXmlWriterSettings = new XmlWriterSettings
    {
        Indent = true,
        OmitXmlDeclaration = false,
        Encoding = Encoding.GetEncoding("ISO-8859-1")
    };

    var oXmlWriter = XmlWriter.Create(oStringWriter,oXmlWriterSettings);
    oXmlSerializer.Serialize(oXmlWriter, obj, oXmlSerializerNamespaces);
    oXmlWriter.Close();
    return oStringWriter.ToString();
}
Source Link
hellowahab
  • 183
  • 1
  • 1
  • 5

Object to xml string implementation

I have recently implemented a code to accomplish Object to string. Can you guys suggest any pros and cons with regard to the code. Any much generalized code would be welcome.

public static string ObjectToXml(object obj)
        {
            var oXmlSerializer = new XmlSerializer(obj.GetType());
            var oStringWriter = new StringWriter();
            var oXmlSerializerNamespaces = new XmlSerializerNamespaces();
            oXmlSerializerNamespaces.Add(string.Empty,string.Empty);
            var oXmlWriterSettings = new XmlWriterSettings
            {
                Indent = true,
                OmitXmlDeclaration = false,
                Encoding = Encoding.GetEncoding("ISO-8859-1")
            };

            var oXmlWriter = XmlWriter.Create(oStringWriter,oXmlWriterSettings);
            oXmlSerializer.Serialize(oXmlWriter, obj, oXmlSerializerNamespaces);
            oXmlWriter.Close();
            return oStringWriter.ToString();
        }