Code
///
/// 将xml字符串反序列化为对象
///
///
///
private object StringDeSerialize(string xmlString,System.Type type)
{
System.Xml.Serialization.XmlSerializer mySerializer = new System.Xml.Serialization.XmlSerializer(type);
TextReader myReader = new StringReader(xmlString);
object obj = mySerializer.Deserialize(myReader);
myReader.Close();
return obj;
}
///
/// 将对象转化成xml字符串
///
///
///
///
private string StringSerialize(object obj,System.Type type)
{
System.Xml.Serialization.XmlSerializer mySerializer = new System.Xml.Serialization.XmlSerializer(type);
StringBuilder xmlString=new StringBuilder(null);
TextWriter myWriter = new StringWriter(xmlString);
System.Xml.Serialization.XmlSerializerNamespaces myNamespaces = new System.Xml.Serialization.XmlSerializerNamespaces();
myNamespaces.Add("xxxxyyy", "http://192.168.15.13/logon.aspx");
mySerializer.Serialize(myWriter,obj,myNamespaces);
myWriter.Close();
return xmlString.ToString();
}
///
/// 将xml字符串反序列化为对象
///
///
///
private object StringDeSerialize(string xmlString,System.Type type)
{
System.Xml.Serialization.XmlSerializer mySerializer = new System.Xml.Serialization.XmlSerializer(type);
TextReader myReader = new StringReader(xmlString);
object obj = mySerializer.Deserialize(myReader);
myReader.Close();
return obj;
}
///
/// 将对象转化成xml字符串
///
///
///
///
private string StringSerialize(object obj,System.Type type)
{
System.Xml.Serialization.XmlSerializer mySerializer = new System.Xml.Serialization.XmlSerializer(type);
StringBuilder xmlString=new StringBuilder(null);
TextWriter myWriter = new StringWriter(xmlString);
System.Xml.Serialization.XmlSerializerNamespaces myNamespaces = new System.Xml.Serialization.XmlSerializerNamespaces();
myNamespaces.Add("xxxxyyy", "http://192.168.15.13/logon.aspx");
mySerializer.Serialize(myWriter,obj,myNamespaces);
myWriter.Close();
return xmlString.ToString();
}