tags:

views:

30

answers:

1

Converting a downloaded query xml string to a usable xml document in vb2005.net

i would like to convert a image query, found here

http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=xxxxxxx&query=cars

in vb2005.net to the xmldocument which i can then cruise around and grab the data with, current code using the webclient isnt giving me a good xml document to use any ideas how i can fix this?

please note that this is within a class so variables have been filled in

Using xkl As New Net.WebClient
        xkl.QueryString = Me.QueryString
        xkl.QueryString.Add("start", Me.ImageOffset)
        xkl.QueryString.Add("appid", searchID)
        If Me.AdultOK Then
            xkl.QueryString.Add("adult_ok", 1)
        Else
            xkl.QueryString.Add("adult_ok", 0)
        End If

        Try
            Dim xbk As New Xml.XmlDocument

            xbk.LoadXml(xkl.DownloadString("http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=xxxxxxx&query=cars"))
            xbk.Normalize()

            If xbk.FirstChild IsNot Nothing Then
                Dim ck = xbk.FirstChild.GetEnumerator
                While ck.movenext

                End While
            End If

        Catch ex As Exception

        End Try
    End Using
A: 

I am presuming that you are saying that LoadXml is throwing an exception when it tries to process the results of DownloadString.

I've had this problem before and for some reason that I have yet to determine there seem to be two chars at the beginning of the string that mess up the XML document. One solution is to just strip off the two characters. I am guessing they have something to do with Byte Order Marks of a UTF document.

The other option is to use the alternative stream based syntax:

xbk.Load(xkl.OpenRead("..."));

Or you could just use the HttpWebRequest class.

Also see this question : http://stackoverflow.com/questions/1317700/strip-byte-order-mark-from-string-in-c

Darrel Miller
i was misreading my information, it was working fine all along just misread the debugger info
Jim