我在 Excel 2003 中使用 VBA 来隔离一些 xml 节点。在返回“未知方法”错误的 xpath 通配符搜索中调用“包含”方法之前,一切都很顺利。
加载xml文件的代码是:
Public Function LoadXml()
strPath = ThisWorkbook.Path & "\V1.xdp"
Set docXml = New MSXML2.DOMDocument
docXml.Load (strPath)
Set LoadXml = docXml
End Function
Run Code Online (Sandbox Code Playgroud)
隔离节点的代码是:
Public Sub TestXpath()
Dim docXml As MSXML2.DOMDocument
Dim NodeList As IXMLDOMSelection
Dim CurrNode As IXMLDOMNode
Dim n As Long
'Identify xpath
Dim strXPath As String
strXPath = "//event/script[contains (text(),'validationScript.errorCount')]"
'Loop through nodes and inspect attributes to ensure we've specified the correct XPath
Set docXml = LoadXml
Set …Run Code Online (Sandbox Code Playgroud)