I have the following fairly simply XML that I'm trying to deserialize:
<props xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://foo.com/bar">
<prop name="foo1" xsi:type="xsd:string">bar1</prop>
<prop name="foo2" xsi:type="xsd:int">2</prop>
</props>
When I run XSD.exe over this XML to produce a schema and then run it again to produce C# classes, I end up with highly-decorated versions of the following:
public partial class props
{
[XmlElement("prop", IsNullable = true)]
propsProp[] Items { get; set; }
}
public partial class propsProp
{
[XmlAttribute]
public string name { get; set; }
[XmlText]
public string Value { get; set; }
}
Now when I try to deserialize the XML into these classes using XmlSerializer, I get the following exception:
System.InvalidOperationException: There is an error in XML document (4, 4). --->
System.InvalidOperationException: The specified type was not recognized: name='string', namespace='http://www.w3.org/2001/XMLSchema', at <prop xmlns='http://foo.com/bar'>.
The xsi:type
attribute is presumably there to facilitate some polymorphism on the prop
value, but I don't care about that - I just want the value in a C# property.
What am I doing wrong here? How can I get that XML into a C# class?