I made a change to the connName[Index] as you suggested in your first question
def env = ['test', 'sandbox']
def connName = ['wba', 'vb', 'cnx', 'rb', 'subinfo']
def xml = '''<connStrings><env name="test"><conn><connName>wba</connName><host>host01</host><port>1500</port><user>wbauser</user><password>wbapassword</password><sid>test</sid></conn><conn><connName>vb</connName><host>host02</host><port>1500</port><user>vbuser</user><password>vbpassword</password><sid>test</sid></conn><conn><connName>cnx</connName><host>host03</host><port>1500</port><user>cnxuser</user><password>cnxpassword</password><sid>test</sid></conn><conn><connName>rb</connName><host>host04</host><port>1500</port><user>rbuser</user><password>rbpassword</password><sid>test</sid></conn></env><env name="sandbox"><conn><connName>wba</connName><host>host01</host><port>1500</port><user>wbauser</user><password>wbapassword</password><sid>sandbox</sid></conn><conn><connName>vb</connName><host>host02</host><port>1500</port><user>vbuser</user><password>vbpassword</password><sid>sandbox</sid></conn><conn><connName>cnx</connName><host>host03</host><port>1500</port><user>cnxuser</user><password>cnxpassword</password><sid>sandbox</sid></conn><conn><connName>subinfo</connName><host>host03</host><port>1500</port><user>subinfouser</user><password>subinfopassword</password><sid>sandbox</sid></conn></env></connStrings>'''
def connStrings = new XmlSlurper().parseText(xml)
//Get details of test environment
def testConnectionDetails = getConnectionDetails(connStrings, env[0], connName[0])
showConnectionDetails(testConnectionDetails, env[0], connName[0])
//Get details of sandbox environment
def sandboxConnectionDetails = getConnectionDetails(connStrings, env [1], connName[1])
showConnectionDetails(sandboxConnectionDetails, env[1], connName[1])
Then I also changed the script to not use a list for connName as you asked in your second question
def env = ['test', 'sandbox']
def connName = 'wba'
//, 'vb', 'cnx', 'rb', 'subinfo']
def xml = '''<connStrings><env name="test"><conn><connName>wba</connName><host>host01</host><port>1500</port><user>wbauser</user><password>wbapassword</password><sid>test</sid></conn><conn><connName>vb</connName><host>host02</host><port>1500</port><user>vbuser</user><password>vbpassword</password><sid>test</sid></conn><conn><connName>cnx</connName><host>host03</host><port>1500</port><user>cnxuser</user><password>cnxpassword</password><sid>test</sid></conn><conn><connName>rb</connName><host>host04</host><port>1500</port><user>rbuser</user><password>rbpassword</password><sid>test</sid></conn></env><env name="sandbox"><conn><connName>wba</connName><host>host01</host><port>1500</port><user>wbauser</user><password>wbapassword</password><sid>sandbox</sid></conn><conn><connName>vb</connName><host>host02</host><port>1500</port><user>vbuser</user><password>vbpassword</password><sid>sandbox</sid></conn><conn><connName>cnx</connName><host>host03</host><port>1500</port><user>cnxuser</user><password>cnxpassword</password><sid>sandbox</sid></conn><conn><connName>subinfo</connName><host>host03</host><port>1500</port><user>subinfouser</user><password>subinfopassword</password><sid>sandbox</sid></conn></env></connStrings>'''
def connStrings = new XmlSlurper().parseText(xml)
//Get details of test environment
def testConnectionDetails = getConnectionDetails(connStrings, env[0], connName[0])
showConnectionDetails(testConnectionDetails, env[0], connName[0])
//Get details of sandbox environment
def sandboxConnectionDetails = getConnectionDetails(connStrings, env [1], connName[1])
showConnectionDetails(sandboxConnectionDetails, env[1], connName[1])
In either case I get the same error
groovy.lang.MissingMethodException: No signature of method: Script12.getConnectionDetails() is applicable for argument types: (groovy.util.slurpersupport.NodeChild, java.lang.String, java.lang.String) values: [wbahost011500wbauserwbapasswordtestvbhost021500vbuservbpasswordtestcnxhost031500cnxusercnxpasswordtestrbhost041500rbuserrbpasswordtestwbahost011500wbauserwbapasswordsandboxvbhost021500vbuservbpasswordsandboxcnxhost031500cnxusercnxpasswordsandboxsubinfohost031500subinfousersubinfopasswordsandbox, ...] error at line: 7
I added the list to connName because I have more than one in each environment. In your example your output is only getting the connection data for env=test and connName=wba but I need to grab all of the connections for each environment and I also would like to not have to update the script whenever I have to add a connection. My original idea was to get a count of connName and then iterate through the file in the env I want to grab all of the connections for that env and I would iterate through the file as many times as the count of connName returned.