I need to deserialize this xml (that I can't change):
<foo:a xmlns:foo="http://example.com">
<b>string</b>
</foo:a>
I made this class:
[DataContract(Name = "a", Namespace = "http://example.com")]
public class A
{
[DataMember(Name = "b", Order = 0)]
public string B;
}
And I did:
using (var streamObject = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
{
var ser = new DataContractSerializer(typeof(A));
return (A)ser.ReadObject(streamObject);
}
I get an object of class A, but the content of B is always null. I know it would work if the xml was using <foo:b>string</foo:b>
, but that is not the case. What can I do to deserialize a DataMember with no namespace?