Android Question How to xml saxparse a web page

Discussion in 'Android Questions' started by Alberto Michelis, May 23, 2015.

  1. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    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 file with my code


    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    Try to open this link in your browser:,ERAR

    You will get the same error message. If you check the page source you will see that the response is not a valid xml string. There is another xml root at the end of the document. You will need to first remove it.
  3. Alberto Michelis

    Alberto Michelis Active Member Licensed 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)
    If Job.Success = True Then
    Log("read OK")
    parser.Parse(Job.GetInputStream, "Parser")
    End If

    End Sub

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

  4. fixit30

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

    Sub JobDone(Job As HttpJob)
    If Job.Success = True Then   
    Log("lectura web OK")
    Log("error de lectura web")
    End If

    End Sub

    Sub StringToInputStream (s As StringAs InputStream
    Dim In As InputStream
       s = s.Replace(
    "<?xml version=""1.0"" encoding=""iso-8859-1""?>""")
       s = s.Replace(
    Dim data() As Byte = s.GetBytes("UTF8")
    In.InitializeFromBytesArray(data, 0, data.Length)
    Return In
    End Sub
  5. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    I'm having problems with this code... please see image, thanks.

    Attached Files:

    • b4a.png
      File size:
      55.9 KB
  6. fixit30

    fixit30 Active Member Licensed User

    Are you sure that you have Initialised parser?

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

    Attached Files:

  7. Alberto Michelis

    Alberto Michelis Active Member Licensed User

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice