使用XML序列化时,如何摆脱的xmlns的 [英] How to get rid of the xmlns when using xml serialization
本文介绍了使用XML序列化时,如何摆脱的xmlns的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不希望以下附加到根元素
I don't want the following to be appended to the root element
的xmlns:XSI =http://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =http://www.w3.org/2001/XMLSchema>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
使用XML序列化时,我应该怎么办。
what should I do when using XML serialization.
推荐答案
通过使用的序列化方式:
public class Foo { }
class Program
{
static void Main()
{
var foo = new Foo();
var serializer = new XmlSerializer(foo.GetType());
var ns = new XmlSerializerNamespaces();
ns.Add(string.Empty, string.Empty);
serializer.Serialize(Console.Out, foo, ns);
}
}
注意最后一个参数( NS
)。
这篇关于使用XML序列化时,如何摆脱的xmlns的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文