XML Deserialization Issue
I have the following xml that's sent to me from a web service. I'm using .NET to deserialize it, but I'm getting an exception saying that its formatted wrong. There is an error in XML document (2, 2) Now, if I understand that correctly, it's not liking that it's finding the first <error> node.
<?xml version="1.0" encoding="UTF-8"?> <messages xmlns="http://www.w3.org/1999/xml"> <error>error text</error> <message>message text</message> </messages>
my code looks like this, data being the String version of the XML above:
Dim resp As cResponseMessage Dim sr As New StringReader(data) Dim xs As New XmlReaderSettings() Dim xd As New XmlSerializer(GetType(cResponseMessage)) resp = xd.Deserialize(XmlTextReader.Create(sr, xs))
and cResponseMessage is simply a class with an XMLRoot attribute and 2 properties with XMLElement attributes. Nothing fancy here, but it doesn't want to work.
Any help would be great.
This class works for me:
<XmlRoot(Namespace:="http://www.w3.org/1999/xml", ElementName:="messages")> _ Public Class cResponseMessage <XmlElement> _ Public Property [error] As String Get Set(ByVal value As String) End Property <XmlElement> _ Public Property message As String Get Set(ByVal value As String) End Property End Class