I am trying to deserialize an Atom xml generated by one of the internal systems. However, when I try:
public static MyType FromXml(string xml)
{
XmlSerializer serializer = new XmlSerializer(typeof(MyType ));
return (MyType) serializer.Deserialize(new StringReader(xml));
}
it throws an exception on the definition of the namespace:
System.InvalidOperationException: <feed xmlns='http://www.w3.org/2005/Atom'> was not expected.
When I add the namespace to the constructor of the XmlSerializer, my object is completely empty:
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
}
Any ideas how can I get it to work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…