我正在尝试反序列化内部系统生成的Atom xml。但是,当我尝试执行以下操作时:
public static MyType FromXml(string xml)
{
XmlSerializer serializer = new XmlSerializer(typeof(MyType ));
return (MyType) serializer.Deserialize(new StringReader(xml));
}
在命名空间的定义上,它会抛出异常:
System.InvalidOperationException: <feed xmlns='http://www.w3.org/2005/Atom'> was not expected.
当我在XmlSerializer的构造函数中添加命名空间时,我的对象完全为空:
public static MyType FromXml(string xml)
{
XmlSerializer serializer = new XmlSerializer(typeof(MyType ), "http://www.w3.org/2005/Atom");
return (MyType) serializer.Deserialize(new StringReader(xml)); //this will return an empty object
}
有什么想法可以让它正常工作吗?