如何将名称空间反序列化为类
本文关键字:反序列化 空间 | 更新日期: 2023-09-27 18:10:34
我需要像这样反序列化XML:
<?xml version="1.0" encoding="utf-8"?>
<ns0:Info xmlns:ns0="http://www.x.com/">
<Name>Anthony</Name>
<Job>Developer</Job>
</ns0:Info>
我使用XSD工具从XSD文档创建了这个类,但是它不能识别NAMESPACES。我怎么能做到呢?我怎样才能改变类来识别它们?我应该改XSD吗?
Thanks in advance
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);