I have a windows service built with VS 2012 vb.net 4.0
I want to desterilize this xml string:
<?xml version='1.0' encoding='UTF-8'?>
<response>
<result numFound="96">
<doc spendingCategory="Assistance">
<record_count>2</record_count>
<UniqueTransactionID>747cd6362dcfa5a2c1b2e49823b3fb5c</UniqueTransactionID> </doc>
<doc spendingCategory="Assistance">
<record_count>3</record_count>
<UniqueTransactionID>6dfae83f273289b0185ba25a821f7e27</UniqueTransactionID> </doc>
<doc spendingCategory="Assistance">
<record_count>4</record_count>
<UniqueTransactionID>3c713f5add6cc3b40042609a7ae5262c</UniqueTransactionID> </doc>
</result>
</response>
Into this structure:
Public Structure response
Dim result As result
End Structure
Public Structure result
Dim numFound As String
Dim doc() As doc
End Structure
Public Structure doc
Dim spendingCategory As String
Dim record_count As String
Dim UniqueTransactionID As String
End Structure
using this code:
Public Shared Sub DeSerialize_Response(ByVal sXML As String, ByRef oResponse As response)
If String.IsNullOrEmpty(sXML) Then
oResponse = Nothing
Exit Sub
End If
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(Schedule))
Dim settings As New XmlReaderSettings()
Using textReader As New StringReader(sXML)
Using xmlReader__1 As XmlReader = XmlReader.Create(textReader, settings)
oResponse = DirectCast(serializer.Deserialize(xmlReader__1), response)
End Using
End Using
End Sub
I am getting this error:
{"There is an error in XML document (2, 2)."} and this in innerEXCEPTION:
<response xmlns=''> was not expected.
Can you tell me what i'm doing wrong with either my structure or my code.
thanks.
Did you not create the file with the same VB library? It should have put a namespace in there.
You can give it a blank namespace when you serialize, something like this (trying to translate from C# in my head).
Open in new window
Or you could add some attributes to your structure like
Open in new window