Forum Discussion

JuliaZ-Williams's avatar
Senior Member
4 years ago

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---------------------------------------

1 Reply

  • richie's avatar
    Community Hero

    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.