一个类前面加了XmlRoot特性,序列化后的xml如何才能不带有任何命名空间
在一个类前面加了[XmlRoot( "test ")]特性,序列化得到的xml的根节点是:
<?xml version= "1.0 " encoding= "utf-16 "?>
<test xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd= "http://www.w3.org/2001/XMLSchema ">
本想要的结果是:
<?xml version=”1.0” encoding=”GBK”?>
<test>
另:如何指定encoding为GBK
------解决方案--------------------XmlSerializer xmls = new XmlSerializer(typeof(MetadataDatabase));
TextWriter tw = new StreamWriter(@ "d:\list.xml ");
//xmls.Serialize(tw, mddb);
XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();
xmlns.Add(string.Empty, string.Empty);
xmls.Serialize(tw, mddb, xmlns);
tw.Close();