Ask a Question

Having trouble getting a node value

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

<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<Chassis:getReportedEventsResponse>
<Chassis:eventList>
<CT:event>
<CT:name>GoodCommunicate</CT:name>
<CT:severity>FIRST-EVENT</CT:severity>
<CT:message>COMM SUCCESS</CT:message>
<CT:filename>svc/Service/ServiceSub.cpp</CT:filename>
<CT:lineNumber>22</CT:lineNumber>
</CT:event>
</Chassis:eventList>
<Chassis:eventList>
<CT:event>
<CT:name>CannotCommunicate</CT:name>
<CT:severity>SECOND-EVENT</CT:severity>
<CT:message>Failed Time</CT:message>
<CT:filename>svc/Service/ServiceSub.cpp</CT:filename>
<CT:lineNumber>32</CT:lineNumber>
</CT:event>

 

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

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

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

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

 

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

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

1 REPLY 1
richie
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:

 

<Books>

<Book>

<Author>value1</Author

<Book/>

<Book>

<Author>value2</Author>

<Book/>

<Books/>

 

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.

 

ta

 

rich

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
cancel
Showing results for 
Search instead for 
Did you mean: