Forum Discussion

Scripter's avatar
Occasional Contributor
9 years ago

Extracting value of an attribute from XML using groovy

I would use same sample xml from my previous post


 <property name="mail">	
       <entry key="server" value="outlook"/>
<property name="housekeep">
	<entry key="files.days" value="60"/>
	<entry key="logs.days" value="30"/>
<property name="ConnectedDB">
	<entry key="name" value="oracle" />
	<entry key="table1" value="tableA" />
	<entry key="table2" value="tableB"/> 

Using groovy, I have to access "oracle". I am hard-coding to get the value of oracle. ..@value[0]


def getxml = new XmlSlurper().parse(new File ('C:/ConfigXML/file.xml'))
def chosenDB{it.@name=='ConnectedDB'}.entry.@value[0] //gives oracle

  Pls suggest without the hard-coded give me the 'value' where 'key'== 'name' from property 'ConnectedDB'



No RepliesBe the first to reply