4

the error message is

msxml3.dll: Unknown method.

/Record/CelloXml/Integration/Case/ServiceEvent[-->last()<--]/Service/Comment

My code looks like this and the error is on the case NEW

Case OLD works fine with [0] in there

'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

for some reason it doesn't like last() is there another way to do this? I need the functionality of the last function, so that if there is only one ServiceEvent node it will still grab that node.


I am not a VBScript Guy (yet) and everything that I have learned about xPath is what I have learned on the job.

asked Dec 16, 2013 at 17:43
1
  • I have the complete working code now posted on CodeReview Commented Dec 17, 2013 at 19:05

2 Answers 2

3

Just add the following property

XmlDoc.SetProperty "SelectionLanguage", "XPath"

My test xml is as follows

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

My test code is as follows

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

I get test4

answered Dec 16, 2013 at 18:13
Sign up to request clarification or add additional context in comments.

1 Comment

I did have to change the index of the other XPath query from [0] to [1] but other than that it worked nicely, I wasn't sure how it would interact with other pieces of the application. but I think it should be fine now. I am going to have to note this for future tokens, I think I can clean the code of a few of them using this.
1
SomeNode[position() = last()]

is what you want.

answered Dec 16, 2013 at 17:49

2 Comments

doesn't like that either, same error except it errors out at position() instead of last()
this worked, but wasn't necessary after I had the property set for the document.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.