您的位置:首页 > 其它

xml 序列化时, 去掉默认的命名空间

2009-03-11 17:25 525 查看
C# 的 xml 序列化时,文档总会带有
xmlns:xsd="http://www.w3.org/2001/XMLSchema"

and

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
如果想去掉,或者添加自己的命名空间,可以考虑下面的做法





//Create our own namespaces for the output
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

//Add an empty namespace and empty value
ns.Add("", "");

//Create the serializer
XmlSerializer slz = new XmlSerializer(someType);

//Serialize the object with our own namespaces (notice the overload)
slz.Serialize(myXmlTextWriter, someObject, ns);


参考:http://www.csharper.net/blog/serializing_without_the_namespace__xmlns__xmlns_xsd__xmlns_xsi_.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: