1
我有以下代码将Object转换为XML并且工作正常。从Object获取纯XML
public static string ConvertObjectToXML(Object obj)
{
String XmlizedString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = null;
if (obj is DerivedClass2)
{
xs = new XmlSerializer(typeof(DerivedClass2));
}
TextWriter w = new StringWriter();
//this.s = new XmlSerializer(this.type);
xs.Serialize(w, notoficationOrder);
w.Flush();
//return w;
XmlizedString = w.ToString();
w.Close();
return XmlizedString.Trim();
}
,并让下面的输出
<?xml version="1.0" encoding="utf-16"?>*
<Obj xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<List>
<!--...-->
</List>
</Obj>
但我不希望XML描绘XML命名空间XD等我需要的下面只有纯粹的对象输出
<Obj>
<List>
<!--...-->
</List>
</Obj>
感谢
海洋
可能的重复问题:http://stackoverflow.com/questions/625927/omitting-all-xsi-and-xsd-namespaces-when-serializing-an-object-in-net – 2011-02-17 19:02:16