用XmlSerializer刪除xsd和xsi前綴

The easiest way to do this is to use an overload of the Serialize method. 

-- StringWriter sw=new StringWriter(); 
   XmlTextWriter tw=new XmlTextWriter(sw); 
   
   XmlSerializerNamespcace xsn=new XmlSerializerNamespaces(); 
   xsn.Add(String.Empty,String.Empty); 
   
   XmlSerializer serializer=new XmlSerializer(typeof(MyObject)); 
   serializer.Serializer(tw,myObject,xsn); 

According to Reflector,the main Serialize method checks if the XmlSerializerNamespace instance is null or has a zero length.If either are true,it uses a default XmlSerializerNampspaces instance which includes the xsd and xsi namespaces. 

Happy programming~

 

from:http://www.cnblogs.com/linhengboy/archive/2005/04/10/135013.html



--------------------------------------------------------------------------------------

另一篇文章http://www.cnblogs.com/Gildor/archive/2010/03/03/1676860.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章