B4J Question XmlSax parser seems very slow / long delay

Discussion in 'B4J Questions' started by lte5000, Apr 8, 2018.

  1. lte5000

    lte5000 Member Licensed User

    Hello all,

    When parsing an approximately 4KB XML file with the XMLSax parser library, it takes around 1 minute to complete.

    I'm wondering if there's something I'm missing (likely), or if there's an issue specific to my system.

    Please see pasted code sample below.

    Thank you for your time!

    Code:
    #Region Project Attributes
       
    #MainFormWidth: 600
       
    #MainFormHeight: 600
    #End Region

    Sub Process_Globals
       
    Private fx As JFX
       
    Private MainForm As Form
       
       
    Dim Tidy As Tidy
       
    Dim Sax As SaxParser
       
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
       MainForm = Form1
       
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
       'MainForm.Show
       DownloadQuote
    End Sub


    Sub DownloadQuote
       
    Dim j As HttpJob
       
    Dim dt,dt1 As Long
       
       j.Initialize(
    "", Me) 'name is empty as it is no longer needed
       j.Download("http://livewatch.lebanonema.org/")
       
    Wait For (j) JobDone(j As HttpJob)
       
    If j.Success Then
           
           
    Tidy.Initialize
           
    Tidy.Parse(j.GetInputStream, File.DirData("LiveWatchMon"), "temp.xml")
           
           
           dt=
    DateTime.now
           
    Try
               
    Dim In As InputStream = File.OpenInput(File.DirData("LiveWatchMon"), "temp.xml")
               
    Log("start parse")
               Sax.Initialize
               Sax.Parse(
    In"sax")
               
    In.Close
               
    Log("finished parse")
           
    Catch
               
    Log(LastException)
           
    End Try
           dt1=
    DateTime.now
           
           
    Log((dt1-dt) / 1000)
           

           
       
    End If
       j.Release
    End Sub


    Sub sax_StartElement (Uri As String, Name As StringAttributes As Attributes)

       
    Log("start element")
       
    End Sub


    Sub sax_EndElement (Uri As String, Name As String, text As StringBuilder)

       
    Log("end element")
       
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The problem is that Tidy adds a DTD declaration to the XML document. The DTD document is then downloaded before the document can be parsed.

    You can solve it with this code:
    Code:
    Tidy.Initialize
    Dim jo As JavaObject = Tidy
    jo.GetFieldJO(
    "tidy").RunMethod("setDocType"Array("omit"))
     
    Mashiane and lte5000 like this.
Loading...
  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