saiyan_prince
7 years agoNew Member
Groovy get node value
Hi,
I'm writing a groovy script to read a JDBC request. I'm having a little trouble in getting the node values.
<Row rowNumber="1"> <JOB_ID>1</JOB_ID> <JOB_TITLE>Public Accountant</JOB_TITLE> <MIN_SALARY>4200.00</MIN_SALARY> <MAX_SALARY>9000.00</MAX_SALARY> </Row>
I want to read the elements inside the Row. getNodeValue() returns null.
def groovyutils = new com.eviware.soapui.support.GroovyUtils(context) def testCase = testRunner.testCase def testStep = testCase.getTestStepByName("JDBC Request") def runner = testStep.run(testRunner, context) def response = runner.getResponseContentAsXml(); def xml = groovyutils.getXmlHolder(response); for( node in xml.getDomNodes("/Results/ResultSet/Row")) { def nodeList = node.getChildNodes() def jobid = node.getChildNodes().item(1).getNodeValue() log.info(jobid)
def jobtitle = node.getChildNodes().item(2).getNodeValue()
log.info(jobtitle) }
Log:
Wed Aug 01 00:09:36 IST 2018: INFO: null
Wed Aug 01 00:09:36 IST 2018: INFO:
Wed Aug 01 00:09:36 IST 2018: INFO: null
Wed Aug 01 00:09:36 IST 2018: INFO:
Wed Aug 01 00:09:36 IST 2018: INFO: null
Wed Aug 01 00:09:36 IST 2018: INFO:
I want to read each element in the Row.
Help will be appreciated!!