[英]How do I get rid of the xmlns declarations inserted by the XmlSerializer?
我有這種類型:
[Serializable, DataContract]
public class A
{
[DataMember(Order = 1)]
public int P1 { get; set; }
[DataMember(Order = 2)]
public XmlSerializableDictionary<string, string> P2 { get; set; }
}
XmlSerializableDictionary
是從.NET XML序列化中獲取的嗎? 。
XmlSerializer
生成以下XML:
<?xml version="1.0"?>
<A xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<P1>17</P1>
<P2>
<item>
<key>
<string>Hello World!</string>
</key>
<value>
<string>xo-xo</string>
</value>
</item>
<item>
<key>
<string>Good Bye!</string>
</key>
<value>
<string>xi-xi</string>
</value>
</item>
</P2>
</A>
我希望擺脫的唯一事情是根元素上的xmlns聲明。 我該怎么做? 謝謝。
通過XmlSerializerNamespaces
:
var ns = new XmlSerializerNamespaces();
ns.Add("", ""); // this line is important... honest!
var ser = new XmlSerializer(type);
ser.Serialize(destination, obj, ns);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.