因此,我通过我的XML文件,这样的迭代:如何存取权限某些XML属性给定节点
def root = new XmlSlurper().parseText(getServiceConfigXml())
println "Project attributes: ${root.attributes()}"
root.project.each { project ->
println "\tProject attributes: ${project.attributes()}"
project.service.each { service ->
println "\t\tService attributes: ${service.attributes()}"
service.receiver.each { receiver ->
println "\t\tReceiver: ${receiver.attributes()}"
receiver.endpoint.each { endpoint ->
println "\t\tEndpoint: ${endpoint.attributes()} - ${endpoint.text()}"
}
receiver.endpoint.each { environment ->
println "\t\tEnvironment: ${environment.attributes()}"
}
}
}
}
这里是一些一个例子中,XML的我通过迭代:
例如<configuration>
<service name='name' pattern='something' isReliable='maybe'>
<receiver name='name' isUsingTwoWaySsl='maybe' isWsRmDisabled='maybe' targetedByTransformation='maybe'>
<endpoint name='local_tst01'>URL</endpoint>
<endpoint name='local_tst02'>URL</endpoint>
<endpoint name='local_tst03'>URL</endpoint>
<environment name='dev' default='local_dev' />
<environment name='tst01' default='test' />
<environment name='tst02' default='local_tst02' />
</receiver>
<operation name='name'>
<sender>sender</sender>
<attribute name='operation' type='String'>name</attribute>
</operation>
</service>
</configuration>
以'receiver'节点为例。从下面这行代码
目前我得到的输出看起来像这样:
接收器:假isWsRmDisabled:假的,isUsingTwoWaySsl:真,名称:CTSS,targetedByTransformation]
${receiver.attributes()}
因此,我不想获取所有的属性,而是想要访问特定的属性。例如name属性,它应该是这样的:
CTSS
这是可能的,没有做任何的子串解决方法吗?
我想象的是这样的:
${receiver.name()}
然而,这输出 '接收器',而不是name属性