Serialize XML objects

 Use this following static method to convert any serilizable object into its string representation 

public static string ToString(object xmlObject)

{

  XmlSerializer xs = new XmlSerializer(xmlObject.GetType());

  StringBuilder sb = new StringBuilder();

  StringWriter sw = new StringWriter(sb);

  string str = string.Empty;

  try

  {

    xs.Serialize(sw, xmlObject);

    str = sw.ToString();

  }

  catch (Exception ex)

  {

  }

  return str;

}

Advertisements