有没有办法配置 XmlSerializer,使其不在根元素中写入默认命名空间?
我得到的是这样的:
<?xml ...>
<rootelement xmlns:xsi="..." xmlns:xsd="...">
</rootelement>
我想删除两个 xmlns 声明。
重复:How to serialize an object to XML without getting xmlns=”…”?
最佳答案
//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)
关于.net - XmlSerializer : remove unnecessary xsi and xsd namespaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/760262/