我有这样的XML,我把它在XML a GPathResult object
我怎样才能Microsoft(R) Windows(R) Server 2003 Enterprise x64 Edition
基于使用常规XML啜如何遍历XML节点并检查属性值?
<client productname="abp">
<machine>
<env>
<variable name='ALLUSERSPROFILE' value='C:\Documents and Settings\All Users' />
<variable name='APPDATA' value='C:\Documents and Settings\Administrator\Application Data' />
<variable name='OS' value='Windows_NT' />
<variable name='COMPUTERNAME' value='AbhishekPC' />
</env>
<osinfo>
<osinfo field='OS Name' information='Microsoft(R) Windows(R) Server 2003 Enterprise x64 Edition' />
<osinfo field='OS Version' information='5.2.3790 Service Pack 2 Build 3790' />
<osinfo field='OS Manufacturer' information='Microsoft Corporation' />
<osinfo field='OS Configuration' information='Standalone Server' />
<osinfo field='OS Build Type' information='Multiprocessor Free' />
</osinfo>
</machine>
</client>
这里与field
值检查为OS Name
被解析代码
def file = new File(filepath)
def gpathResult = new XmlSlurper().parse(file)
[email protected]()
log.info [email protected]()
System.out.println("HI 1"[email protected]());
System.out.println("HI 2"[email protected]());
if([email protected]().equals("OS"))
{
[email protected]ext()
}
if([email protected]().equals("COMPUTERNAME"))
{
[email protected].text()
}
这里HI 1
打印所有的环境名称属性值,但HI 2
只打印HI 2
这里是快照
这里是解决后,我走过
def vals1=gpathResult.machine.env.variable.findAll{[email protected]=='COMPUTERNAME'}[email protected]()
println vals1
csmSummary.hostname=vals1
def vals2=gpathResult.machine.env.variable.findAll{[email protected]=='OS'}[email protected]()
println vals2
csmSummary.osname=vals2
你有你所使用的XML解析成'gpathResult'变量的代码? – 2011-05-17 08:40:19
@tim_yates:我有,我会在一分钟内发布它 – abi1964 2011-05-17 08:43:13
@tim:我编辑我的问题 – abi1964 2011-05-17 08:48:05