0
我有這個奇怪的問題,通過XMLSlurper在groovy中解析xml,它將大小顯示爲0.無法找出原因。通過XML解析Groovy中的XML Slurper
我的XML文件看起來像:
<?xml version="1.0" encoding="iso-8859-1"?>
<sites>
<site name="OctUK">
<property name="warName">OctUKbuild-Deployable</property>
</site>
<site name="GbsJP">
<property name="warName">GbsJPbuild-Deployable</property>
</site>
</sites>
代碼:
findSite("${project.GTA_BUILD_HOME}/platforms/pos/config/pos-sites.xml")
//Passed the path of the xml file to the method below:
GPathResult findSite(String sitesXml) {
xmlConfig = new XmlSlurper().parse(new File(sitesXml))
def siteGPath = xmlConfig.sites.site.findAll
// Check that a POS-sites.xml is valid
assert siteGPath.size() != 0, 'Error: no site found'
return(siteGPath)
}
的方法失敗,錯誤說法錯誤:沒有網站發現,因爲它給siteGPath的結果爲0。不知道爲什麼它給結果爲0.它應該有大小爲2.
有什麼問題我在做什麼。任何幫助深表感謝。我被困在這一點上。
感謝蒂姆。我現在修改了我的代碼來定義siteGPath = xmlConfig.site – user1470220