如何在Groovy中附加多个字符串?

如何在Groovy中附加多个字符串?,groovy,Groovy,我正在Groovy中解析一个XML文件,稍后需要附加返回的变量 def lmList = slurperResponse.LastGlobal.HeatMap String appendedString = lmList.country + lmList.ResponseTime + lmList.timeset 这不适用于附加3个字符串。它只是将第一个字符串分配到右边。如何在Groovy中正确地实现它?我尝试了concat,它抛出了以下错误: groovy.lang.MissingMetho

我正在Groovy中解析一个XML文件,稍后需要附加返回的变量

def lmList = slurperResponse.LastGlobal.HeatMap
String appendedString = lmList.country + lmList.ResponseTime + lmList.timeset
这不适用于附加3个字符串。它只是将第一个字符串分配到右边。如何在Groovy中正确地实现它?我尝试了
concat
,它抛出了以下错误:

groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.NodeChildren.concat() is applicable for argument types: (groovy.util.slurpersupport.NodeChildren) values: [4468]
Possible solutions: toFloat(), collect(), collect(groovy.lang.Closure)
at 

Yor代码应如下所示:

String appendedString = "${lmList.country}${lmList.ResponseTime}${lmList.timeset}"

您得到的异常意味着您正试图调用
plus()/concat()
方法,该方法不是由
NodeChildren提供的

String appendedString = "${lmList.country}${lmList.ResponseTime}${lmList.timeset}"

您得到的异常意味着您正试图调用
plus()/concat()
方法,该方法不是由
NodeChildren

作为injecteer的替代方法提供的-

def lmList = slurperResponse.LastGlobal.HeatMap
String appendedString = lmList.country.toString() + lmList.ResponseTime.toString() + lmList.timeset.toString()

您没有尝试添加字符串,而是尝试添加碰巧包含字符串的节点。

作为injecteer的替代方案-

def lmList = slurperResponse.LastGlobal.HeatMap
String appendedString = lmList.country.toString() + lmList.ResponseTime.toString() + lmList.timeset.toString()

您没有尝试添加字符串,而是尝试添加碰巧包含字符串的节点。

假设xml如下所示:

def xml = '''
<Root>
    <LastGlobal>
        <HeatMap>
            <Country>USA</Country>
            <ResponseTime>20</ResponseTime>
            <TimeSet>10</TimeSet>
        </HeatMap>
    </LastGlobal>
</Root>
'''

假设xml看起来像:

def xml = '''
<Root>
    <LastGlobal>
        <HeatMap>
            <Country>USA</Country>
            <ResponseTime>20</ResponseTime>
            <TimeSet>10</TimeSet>
        </HeatMap>
    </LastGlobal>
</Root>
'''

你能给出一些示例XML吗?你能给出一些示例XML吗?我确实喜欢你的代码应该像:-非常好:)我确实喜欢你的代码应该像:-非常好:)