Search code examples
basic4android

How do you convert a string into an InputStream


I want to use the SaxParser to parse a string that contains XML code I got using the HTTPUtils.

Can you tell me how to convert the string I got from the HTTPUtils into an InputStream?

I tried to do this but it won't let me compile it:

Sub JobDone (Job As String)

    Dim strStringFromWebSite As String
    Dim in As InputStream

    If HttpUtils.IsSuccess(strUrlToCall) Then

        strStringFromWebSite = HttpUtils.GetInputStream(strUrlToCall)

        in = strStringFromWebSite
        XmlParser.Parse(in, "Parser")
        in.Close
    Else
        ToastMessageShow("There was a problem getting a response from the web site.", False)
    End If
End Sub

I get the error on this line of code:

in = strStringFromWebSite

Thanks.


Solution

  • HttpUtils.GetInputStream returns an InputStream (as it's name indicates). Why are you trying to convert it to a string and then back to an InputStream? It seems to me you can go direct and cut out the middleman. :)

    in = HttpUtils.GetInputStream(strUrlToCall)
    XMLParser.Parse(in, "Parser")