Android Question Get Document Text of HTML/XML

Jan Van Gastel

Member
Licensed User
I am building an APP which communication with a PLC. I want to read out status of hardware inputs and outputs. My PLC can give this information with XML pages. So I need to read out a XML page.

I already did this in VB.NET. I used a WebView and downloaded the documenttext of the XML to a string. This string I used for getting the right information.

But how does it works in Android ?
I've read something of HTTPutils2, but it does not work...
 
OK, thanks but help me (I'm a B4A beginner :) ).

This is my simple test code, for example try to retrieve document text of google.
With download2, i dont understand the seconde parameter (array).


Sub Globals

Private HTMLDocumentText As String
Dim Job As HttpJob

End Sub

Sub Activity_Create(FirstTime As Boolean)

Job.Initialize("Job1", Me)
Job.Download2("http://www.google.be",Array As String("first key", "first value :)", "second key", "value 2"))

End Sub

Sub JobDone (Job As HttpJob)

If Job.Success = True Then
HTMLDocumentText = Job.GetString

End If

End Sub
 
Upvote 0
Does the JobDone or Job.Success have special criteria to say "done" or "success" ? Because when I download google, it is succesful and I can see the document text.

When I download my XML, it does not reply with success.

this is how my XML looks like in a PC browser

Code: Copy
<JVG-7-ON>
<uitgang1>0 </uitgang1>
<uitgang2>0 </uitgang2>
<uitgang3>0 </uitgang3>
<uitgang4>0 </uitgang4>
<uitgang5>0 </uitgang5>
<uitgang6>0 </uitgang6>
<uitgang7>0 </uitgang7>
<uitgang8>0 </uitgang8>
<uitgang9>0 </uitgang9>
<uitgang10>0 </uitgang10>
<uitgang11>0 </uitgang11>
<gewtemp_grslpk>205 </gewtemp_grslpk>
<gewtemp_klslpk>205 </gewtemp_klslpk>
<gewtemp_badk>205 </gewtemp_badk>
<temp_grslpk>2156 </temp_grslpk>
<temp_klslpk>2116 </temp_klslpk>
<temp_badk>2152 </temp_badk>
<temp_stuur>230 </temp_stuur>
</JVG-7-ON>
 
Upvote 0
if the request is valid (and the server properly configured) then you get the error in JobDone (react on errors) ... If all is ok then success should be true and the xml should be delivered in JobDone...

Code: Copy
If Job.Success = False Then
        Log(Job.ErrorMessage)
 
Upvote 0
I think the Job desires another result in the code...:
it is the first word of my xml code.

Code: Copy
java.net.ProtocolException: Unexpected status line: <STATUS>
 
Last edited:
Upvote 0
Yes,

It gives my the XML with the tags filled by the PLC, but in the header I can see a message:

"this xml file does not apper to have any style information associated with it. The document tree is shown below."
 
Upvote 0
that is normal because it's missing the xml definition tag.

does it download the content? can you see the xml when doing a log(job.getstring) ?
 
Upvote 0
I'm sorry, but the program is new for me.
I've did log(job.getstring), I suppose the logging is going to the log frame at the right of the screen ?
The only thing I get is this

Code: Copy
** Activity (main) Pause, UserClosed = false **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
java.net.ProtocolException: Unexpected status line: <STATUS>
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
** Service (starter) Destroy **

"Status" is the first word of my XML, so I think the job downloads the string. Only it occurs an error.
 
Upvote 0
I think that PLC is not sending out the required headers it's checking on to know the download status or server response codes.
 
Upvote 0
I can change the XML of my PLC as I want.
I've uploaded an empty XML page.

Code: Copy
<?xml version="1.0" ?>
<metadata>
</metadata>

and it stills give me the error.

Code: Copy
java.net.ProtocolException: Unexpected status line: <?xml version="1.0" ?>
 
Upvote 0
try to put it on you own computer. use serva or something as portable webserver.

if that works fine then it's the PLC that doesn't send http headers with the response.
 
Upvote 0
You are right, I've hosted the same file on a webhost, and it works... The job is succesful done.
However, can I ignore the error and get the string ?
 
Upvote 0
give it a try. put that log(job.getstring) as first line of that sub and you'll know.
 
Upvote 0
Back
Top