I’m having issues trying to deserializing my xml string that was from a dataset..
Here is the XML layout..
<DataSet>
<User>
<UserName>Test</UserName>
<Email>test@test.com</Email>
<Details>
<ID>1</ID>
<Name>TestDetails</Name>
<Value>1</Value>
</Details>
<Details>
<ID>2</ID>
<Name>Testing</Name>
<Value>3</Value>
</Details>
</User>
</DataSet>
Now I am able to deserialize the “UserName” and “Email” when doing
public class User
{
public string UserName {get;set;}
public string Email {get;set;}
public Details[] Details {get;set;}
}
public class Details
{
public int ID {get;set;}
public string Name {get;set;}
public string Value {get;set;}
}
This deserializes fine when I just get the user node, the Details isnt null but has no items in it..
i know I am suppose to have between all the details but I rather not modify the XML, anyways to get this to deserialize properly without recreating the XML after I get it?
I assume you are trying to use XmlSerializer? If so, you just need to add the
[XmlElement]attribute to the Details member. This might not seem intuitive, but this tells the serializer that you want to serialize/deserialize the array items as elements rather than an array with the items as child elements of the array.Here is a quick example