Forum Discussion
I assume that you are using a Directory Data Source to read each files contents in turn. and that data source has a single property called "contents", you can use a Groovy test step within your data source loop and the XmlSlurper to interogate your XML.
import groovy.util.XmlSlurper
// Get XML from data source property
//def xmlText = context.expand( '${DataSource#contents}' )
//Example XML just to demo XmlSlurper
def xmlText = '''<element1>
<element2>
<element3 RecordID='123'>fred</element3>
</element2>
</element1>
'''
def xml = new XmlSlurper().parseText(xmlText)
log.info(xml.element2.element3.@RecordID)
My script above just logs the record ID, you could easily set a property of a JDBC test step.
More info on the XmlSlurper can be found here:
Hey Radford
Thanks for reply - I do appreciate it!
I edited the file as implied (see below) but I'm getting an org.xml.sax.SAXParseException; Premature end of file. error at line :14 response.
I'm not a coder - I spent a couple of hours trying to work out the problem but the google help is talking about instreams/outstreams and I just haven't got a clue! The data files in the directory are all wellformed.
import groovy.util.XmlSlurper
// Get XML from data source property
def xmlText = context.expand( '${DataSource#contents}' )
//Example XML just to demo XmlSlurper
//def xmlText = '''<element1>
// <element2>
// <element3 RecordID='123'>fred</element3>
// </element2>
//</element1>
//'''
def xml = new XmlSlurper().parseText(xmlText)
log.info(xml.element2.element3.@RecordID)
I'm totally lost!
Thanks again!