Solved

No results from deserializing an XML string

Posted on 2013-06-05
3
276 Views
Last Modified: 2013-08-01
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:



    <XmlRoot("response")>
    Public Structure response
        Dim result As result
    End Structure
    Public Structure result
        Dim numFound As String
        <XmlArray>
        <XmlArrayItem("doc")>
        Dim doc As List(Of doc)
    End Structure



This is the code I am using for deserialization :


    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(response), New XmlRootAttribute("response"))
        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

can you see why  my oResponse.result.doc object has a count of 0 and my numFound is "nothing"
0
Comment
Question by:cnxmax
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39224755
can u post the doc structure?
0
 

Author Comment

by:cnxmax
ID: 39226599
here is the doc structure:

Public Structure doc
        Dim spendingCategory As String
        Dim record_count As String
        Dim UniqueTransactionID As String
end structure
0
 

Author Closing Comment

by:cnxmax
ID: 39373899
thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now