B4J Question XML XPath?

jmon

Well-Known Member
Licensed User
Longtime User
hello,

I was wondering if there was a way to parse XML files with XPath or something similar. I think that Saxml is slow when I need to retreive a single information in a big XML file, because it has to process the whole file. Or is there a way to stop the parser once I got the information needed?

thanks.
 

jmon

Well-Known Member
Licensed User
Longtime User
Sax parsers are actually faster than other parsers. You should test it in release mode it should be fast.
Thank you. It is indeed faster in release mode, almost instantaneous.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
I wrote a sub that simulates (in a very basic way) the Xpath, so at least I know exactly where I am:
B4X:
Sub parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
    If Xpath(parser.Parents).ToLowerCase = "xmeml/bin/children/clip" Then
        Select Name
            Case "duration"
                Log("Duration")
            Case "name"
                Log("Name")
        End Select  
    End If
End Sub

Sub Xpath(l As List) As String
    Dim s As StringBuilder : s.Initialize
    For Each e As String In l
        If s.Length > 0 Then s.Append("/")
        s.Append(e)
    Next
    Return s.ToString
End Sub

So this way, I can check the full path of the line currently parsed.
 
Upvote 0
Top