Android Question How to xml saxparse a web page

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Hi,
I´ve modifed the SaxXml parser example to read a xml provided by a web page.
All seams to go well but at the end of the Parsing I got an error like:

Error occurred on line: 61 (main)
org.apache.harmony.xml.ExpatParser$ParseException: At line 42, column 0: junk after document element

Line 61 is the End If of the Parser routine.

Attached is the XmlSax.zip file with my code

Thanks
 

Attachments

Thanks I how do I remove this last two lines, I have no control of the html server.
I am using...

Sub JobDone(Job As HttpJob)
Log("***JObDone")
If Job.Success = True Then
Log("read OK")
Log(Job.GetString)
parser.Parse(Job.GetInputStream, "Parser")
Else
Log("error")
Log(Job.ErrorMessage)
End If

End Sub

Sendig a Job.GetInputStream to the parser
How can I remove those lines from the GetImputStream?

Thanks
 
Upvote 0
If you have no control over the Webserver then you will need to strip out the Bad Xml yourself before sending it to XmlSax.

Something like the below.

Code: Copy
Sub JobDone(Job As HttpJob)
    Log("***JObDone")
    If Job.Success = True Then   
        Log("lectura web OK")
         Log(Job.GetString)
        parser.Parse(StringToInputStream(Job.GetString), "Parser")
    Else   
        Log("error de lectura web")
        Log(Job.ErrorMessage)
    End If

End Sub

Sub StringToInputStream (s As String) As InputStream
   Dim In As InputStream
   s = s.Replace("<?xml version=""1.0"" encoding=""iso-8859-1""?>", "")
   s = s.Replace("<ajax-response></ajax-response>", "")
   Dim data() As Byte = s.GetBytes("UTF8")
   In.InitializeFromBytesArray(data, 0, data.Length)
   Return In
End Sub
 
Upvote 0
I'm having problems with this code... please see image, thanks.
 

Attachments

  • b4a.png
    b4a.png
    55.9 KB · Views: 522
Upvote 0
Are you sure that you have Initialised parser?

Code: Copy
parser.Initialize

The attached modified example that you provided above works fine on my device.
 

Attachments

Upvote 0
Back
Top