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

  • XmlSax.zip
    11.8 KB · Views: 182

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
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

fixit30

Active Member
Licensed User
Longtime User
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.

B4X:
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

fixit30

Active Member
Licensed User
Longtime User
Are you sure that you have Initialised parser?

B4X:
parser.Initialize

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

Attachments

  • XmlSax.zip
    5.3 KB · Views: 194
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…