XML deserialization problem

I have the following xml being sent to me from a web service. I am using .NET to deserialize it, but I am getting an exception saying that it is not formatted correctly. There is an error in XML document (2, 2)

Now if I understand this correctly, I don't like that it finds 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, the data is the XML version String

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 just a class with an attribute XMLRoot

and 2 properties with attributes XMLElement

. Nothing fancy here, but he doesn't want to work.

Any help would be great.

0


source to share


2 answers


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

      

+1


source


The error in the XML document (2, 2) looks like it would be m in <messages>.



Perhaps you don't have the correct XmlRoot setting in your cResponseMessage?

0


source







All Articles