excel - 在 Excel VBA 中使用 SAXXMLReader60 解析多个非常大的文件。如何停止解析文档并转到下一个文件?
问题描述
我试图在 Excel VBA 中相对快速地解析大型 XML 文件。在每个文件中,我只需要从前几个元素中获取信息,然后需要退出解析并转到下一个文件。我实现了 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
解决方案
推荐阅读
- python - 如何通过任务调度程序调度 python 脚本从虚拟环境运行
- typescript - 开玩笑地测试异常
- vue.js - vuetify v-select 的 vue-material-dashboard 问题
- python - 使用键和值作为子列表反转字典
- android - 某些文件已损坏
- git - 如何添加子模块作为对存储库的引用?
- android - Firebase 云消息传递。令牌检索失败:SERVICE_NOT_AVAILABLE
- c - 如何动态获取整数输入并在按 Enter 时终止循环?
- microsoft-cognitive - 为什么表单识别器返回的“boundingBox”坐标对于我的 PDF 表单似乎不正确?
- sql-server - 执行 SQL 任务的行为不同的加载开始日期和结束日期