2013-12-16 21 views
2

錯誤消息運行是未知的方法通過的VBScript

MSXML3.DLL:未知方法。

/錄音/ CelloXml /集成/套/ ServiceEvent [ - >末頁()< - ] /服務/評論

我的代碼看起來像這樣和錯誤接通的情況下NEW

案例OLD[0]在那裏

'On Error Resume Next 

Public Function GetParameterXml() 
GetParameterXml = _ 
"<Parameters>" &_ 
    "<Parameter Value='Age' Code='A' Description='Age' Type='Combo' Tooltip='Would you like the newest or oldest Reason?'>" &_ 
    " <Options>" &_ 
    " <Option Code='O' Description='Oldest' Value='OLD' />" &_ 
    " <Option Code='N' Description='Newest' Value='NEW' />" &_ 
    " </Options>" &_ 
    "</Parameter>" &_ 
"</Parameters>" 
End Function 

'Parameter Variables 
Dim Age : Set Age = Parameters.Item(Bookmark , "Age") 

' PlaceHolder Variables 
Dim CommentNodes 

''' stop here and look around 
stop 

Select Case Age.Value 
Case "OLD": 
    Set CommentNodes = XmlDoc.SelectNodes("Record/CelloXml/Integration/Case/ServiceEvent[0]/Service/Comment") 
Case "NEW": 
    Set CommentNodes = XmlDoc.SelectNodes("Record/CelloXml/Integration/Case/ServiceEvent[last()]/Service/Comment") 
End Select 

For Each CommentNode In CommentNodes 
ReturnData = ReturnData & CommentNode.Text & MD 
Next 

If Len(ReturnData) > 0 Then 
ReturnData = Left(ReturnData, Len(ReturnData) - Len(MD)) 
Else 
ReturnData = vbNullString 
End If 

一些REA工作正常兒子它不喜歡last()有沒有另外一種方法來做到這一點?我需要最後一個函數的功能,所以如果只有一個節點,它仍然會抓取該節點。


我不是一個VBScript蓋伊()和一切,我已經瞭解XPath是什麼,我都在工作中的經驗教訓。

+0

我有完整的工作公司現在發佈在[CodeReview](http://codereview.stackexchange.com/q/37254/18427) – Malachi

回答

2

只需添加以下屬性

XmlDoc.SetProperty "SelectionLanguage", "XPath" 

我的測試XML是如下

<root> 
    <child1> 
     <child2> 
      <child3>test1</child3> 
     </child2> 
     <child2> 
      <child3>test2</child3> 
     </child2> 
     <child2> 
      <child3>test3</child3> 
     </child2> 
     <child2> 
      <child3>test4</child3> 
     </child2> 
    </child1> 
</root> 

我的測試代碼如下

strXMLReadFile = "C:\Test.xml" 

Set xmlDoc = CreateObject("Microsoft.XMLDOM") 
xmlDoc.SetProperty "SelectionLanguage", "XPath" 
xmlDoc.Async = False 
xmlDoc.Load(strXMLReadFile) 

Set nodeXML = xmlDoc.SelectNodes("//root/child1/child2[last()]") 
msgbox nodeXML(0).Text 

我得到test4

+0

我確實必須將另一個XPath查詢的索引從'[0]'更改爲'[1]',但除此之外它運行良好,我不確定它如何與其他應用程序交互。但我認爲現在應該沒問題。我將不得不注意這個未來的令牌,我想我可以使用它清理其中一些代碼。 – Malachi

1
SomeNode[position() = last()] 

是你想要的。

+0

不喜歡那樣,同樣的錯誤,除了它錯誤在'position()'而不是'last() ' – Malachi

+0

這個工作,但沒有必要後,我有文件的屬性設置。 – Malachi

相關問題