В Excel VBA используется SAXXMLReader60 для анализа нескольких очень больших файлов. Как прекратить разбор документа и перейти к следующему файлу? - PullRequest
1 голос
/ 16 октября 2019

Я пытаюсь относительно быстро проанализировать большие XML-файлы в Excel VBA. В каждом файле мне нужно только получить информацию из первых нескольких элементов, затем выйти из парсинга и перейти к следующему файлу. Я реализовал ContentHandlerError, но не вижу, как его вызвать, чтобы изящно вернуться в цикл и проанализировать следующий файл. Вот код, я очень признателен за любую помощь!

Sub main()

    Dim saxReader As SAXXMLReader60
    Dim saxhandler As ContentHandlerImpl
    Dim saxerror As ContentHandlerError
    Dim sFolder As String
    Dim sFile As String
    Dim sFilePath As String

    sFilePath = "c:\testfiles\"
    sFolder = sFilePath & "*.xml"

    sFile = Dir(sFolder)

    Do While Len(sFile) > 0
        Debug.Print sFile

        Set saxReader = New SAXXMLReader60
        Set saxhandler = New ContentHandlerImpl
        Set saxerror = New ContentHandlerError

        Set saxReader.contentHandler = saxhandler
        Set saxReader.errorHandler = saxerror

        saxReader.parseURL "file://" & sFilePath & sFile

        Set saxReader = Nothing

        sFile = Dir
    Loop

End Sub

Private Sub IVBSAXContentHandler_endElement(strNamespaceURI As String, strLocalName As String, strQName As String)

    If strLocalName = "Series" Then

        'TODO:How to stop processing and go to next file?
    End If

End Sub
...