How do you convert a string into an InputStream

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

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:
B4X:
Sub JobDone (Job As String)
    
   Dim strStringFromWebSite As String
     Dim in As InputStream

    If HttpUtils.IsSuccess(strUrlToCall) Then
        
      strStringFromWebSite = HttpUtils.GetString(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:
B4X:
in = strStringFromWebSite

Thanks.
 

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Erel,

Thanks for the reply.

I tried GetImputStream but still can't compile on the same line of code giving this error:

B4X:
Compiling code.                         0.08
Generating R file.                      0.00
Compiling generated Java code.          Error
B4A line: 560
in = strStringFromWebSite
javac 1.6.0_26
src\dawah\doors\people.java:1061: inconvertible types
found   : java.lang.String
required: java.io.InputStream
_in.setObject((java.io.InputStream)(_strstringfromwebsite));

Can you edit my code and show me how to do it?

Thanks.


You should call HttpUtils.GetInputStream instead of GetString.
 
Upvote 0

Dan Harding

Member
Licensed User
Longtime User
I was hoping for an answer to the original question. What if the XML is coming from a database and I read it into a string. How do I parse it from there?

Thanks for the help.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…