我在 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
隔离节点的代码是:
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 NodeList = docXml.SelectNodes(strXPath)
For n = 0 To (NodeList.Length - 1)
Set CurrNode = NodeList.Item(n)
InspectNode CurrNode
Next
ExitSub:
Set docXml = Nothing
Exit Sub
End Sub
我有一个 MSXML v6 的参考集。知道为什么我会收到“未知方法”错误吗?
谢谢
乔恩