Showing results for 
Search instead for 
Did you mean: 

Having trouble getting a node value

Senior Member

Having trouble getting a node value

I need a few node values, the script assertion below gives me the same (first) node value, and if I try (in the secondResponse) something like ("//Chassis:eventList/Chassis:eventList/CT:event/CT:message") the return value is null.

 Any suggestions on how I get the second Node value if my (example - excerpt) response appears as follows?:

---------------------Soap response template--------------------------------------------

<CT:message>COMM SUCCESS</CT:message>
<CT:message>Failed Time</CT:message>


----------------------------------Script assertion--------------------------------------------

def groovyUtils = new

def holder = groovyUtils.getXmlHolder('getReportedEvents #Response')

//send each event to a variable
def firstEvent = holder.getNodeValue("//CT:event/CT:message")"\t\t$firstEvent\r\n")


def secondEvent = holder.getNodeValue("//CT:event/CT:message")"\t\t$secondEvent\r\n")

----------------------------------------------End script assertion---------------------------------------

Community Hero

Re: Having trouble getting a node value

Hey @JuliaZ-Williams 


you reckon you need to differentiate between the two using the correct index value.


jsonpath starts with zero, but  i think xpath starts with 1, so using the following as an example:











So including the index, the xpath to the first instance of 'Author' tag would be //Books/Book[1]/Author and xpath to the second instance of Author tag would be something like //Books/Book[2]/Author


OR thereabouts - it's been awhile since I was playing with xpath - just been focused on jsonpath for hte last couple of years.





if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
New Here?
Join us and watch the welcome video:
Top Kudoed Authors