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.

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

Need Your Help

How to use strtok to separate specific string to array by two delimiter

c split strtok

I have strings like this +100+200,300+500+400,700,900. I need to split the string to array by two different symbols '+' and ',', so I would like to get A's id = 100 and it's child arrayA [200, 300]...

Float getting truncated in teradata sql

sql teradata

Teradata Float datatype truncates decimal value to 2 decimal point.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.