0

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 isn't giving me a good xml document to use. Any ideas how I can fix this?

pPlease 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
MPelletier
  • 16,256
  • 15
  • 86
  • 137
Jim
  • 601
  • 6
  • 17

1 Answers1

0

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 : Strip Byte Order Mark from string in C#

Community
  • 1
  • 1
Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
  • i was misreading my information, it was working fine all along just misread the debugger info – Jim Sep 22 '09 at 03:35