我在VBA改變每個循環成環
Dim userBeanList As MSXML2.IXMLDOMNodeList
Dim userbean As MSXML2.IXMLDOMNode
Dim beanChild As MSXML2.IXMLDOMNode
XMLDOC.Load ("https://www.catch.api")
r = 4
Set userBeanList = XMLDOC.SelectNodes("/response/responseBody/responseList/item[recordType='TPI']")
For Each userbean In userBeanList
For Each beanChild In userbean.ChildNodes
If beanChild.nodeName = "catch" Then GoTo NextIteration
Sheets("Sheet2").Cells(r, 1) = beanChild.nodeName
Sheets("Sheet2").Cells(r, 2) = beanChild.Text
r = r + 1
NextIteration:
Next beanChild
Next userbean
下面的代碼目前,我公司通過所有的節點,然後在這種情況下,忽略了節點稱爲「捕獲」循環再進入下一個迭代,因爲我不需要該節點或節點值。 而不是這樣做我怎麼會改變我的循環到一個我可以直接去感興趣的節點,因此不必跳過似乎效率低下的迭代?
/////之後,從凍糕
Dim userBeanList As MSXML2.IXMLDOMNodeList
Dim userbean As MSXML2.IXMLDOMNode
Dim beanChild As MSXML2.IXMLDOMNode
XMLDOC.Load ("http://www.catch.api")
r = 4
Set userBeanList = XMLDOC.SelectNodes("/response/responseBody/responseList/item[recordType='TPI']/*[not(local-name)='catch']")
For Each userbean In userBeanList
Sheets("Sheet2").Cells(r, 1) = userbean.nodeName
Sheets("Sheet2").Cells(r, 2) = userbean.Text
r = r + 1
Next userbean
http://stackoverflow.com/questions/24188773/xpath-to-select-all-and-exclude-child-and-its-children –
它可能會更高效地說它beanChild.nodeName <>「catch」然後做東西 – justkrys