Android Question stop parsing xmlparser

Discussion in 'Android Questions' started by EddyW, Jul 8, 2015.

  1. EddyW

    EddyW Member Licensed User

    After receiving the xml (httputils2 + OkHttp lib), i parse the xml and it works fine.

    in the Parser_EndElement i check/read the <Code> and <Opmerking> tag and all other tags i dont need at this stage. How can i stop the parsing of the xml after i have the 2 tags i need?

    Below is a simple example of the xml i receive. The <Taken> hold normal much more data and takes a while to process each tag and

    -- XML Exampe ---
    <Status>
    <Code>1</Code>
    <Opmerking>Mesage recieved corectly</Opmerking>
    </Status>
    <Taken>
    <Taak><TaakId>1</TaakId></Taak>
    <Taak><TaakId>2</TaakId></Taak>
    </Taken>
    -- XML Exampe ---

    Each XML i receive has a <Status> with CODE and Opmerking but below </Status> can be different.
    Code is use for parsing i tried return to stop parsing but that dont work.

    Code:
    Public Sub GetStatus As Map
        parser.Parse(GetInputStream, 
    "Parser")     
        
    Return mStatus
    End Sub

    Sub  Parser_StartElement (Uri As String, Name As StringAttributes As Attributes)
        
    If Name.ToUpperCase = "STATUS" Then
            
    If mStatus.IsInitialized = False Then
                mStatus.Initialize
            
    End If
        
    End If
    End Sub

    Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
        
    Select Name.ToUpperCase
        
    Case "CODE"
            mStatus.Put(
    "Code",Text.ToString)
        
    Case "OPMERKING"
            mStatus.Put(
    "Opmerking",Text.ToString)
        
    Case "STATUS"
            
    Return
        
    End Select
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Unless the xml is huge you can just ignore the events. Use a process global variable as a flag.
     
Loading...