Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want deserialize xml data.

Here is my code..
================

XML
string ss = @"<IsValidAdminUserResponse><IsValidStatus><a:AdminMasterDC><a:AuthKey>Valid</a:AuthKey><a:RtnMessage>success</a:RtnMessage><a:EmailAddress>support@abc.com</a:EmailAddress><a:UserId>1</a:UserId><a:HubId>22</a:HubId></a:AdminMasterDC></IsValidStatus></IsValidAdminUserResponse>";
                
                var reader = new StringReader(ss);
                var serializer = new XmlSerializer(typeof(IsValidStatu));
                var instance = (IsValidStatu)serializer.Deserialize(reader);
                MessageBox.Show(instance.RtnMessage);




C#
public class IsValidStatu
        {
            public string AuthKey { get; set; }
            public string RtnMessage { get; set; }
            public string EmailAddress { get; set; }
            public string UserId { get; set; }
            public string HubId { get; set; }
        }


================

I get error "There is an error in XML document (1,2)"
How do i resolve error?

Please help me.

Thanks
Posted
Comments
Nathan Minier 17-Sep-14 8:40am    
Cut out the IsValidAdminUserResponse and a:AdminMasterDC tags in your test string and it should work correctly. Your attempted to serialize to a reflected model and it's not writing properly, as the properties don't match and you've wrapped it in the string.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900