我有這樣的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