【发布时间】:2011-02-03 20:30:38
【问题描述】:
您好,我是 groovy 新手,我对 groovy 如何解析 xml 有一个误解
<schema-definition name="Standard" >
<field-type name="Standard:Integer" descr="A whole number." base-type="long"/>
<field-type name="Standard:Boolean" descr="A boolean value." base-type="boolean"/>
<field-type name="Standard:String" descr="A string" base-type="string"/>
</schema-definition>
当我尝试时
document = groovy.xml.DOMBuilder.parse(new FileReader('D:/test.xml'))
rootElement = document.documentElement
use(groovy.xml.dom.DOMCategory)
{
field-types=rootElement.field-type
println field-types
}
我什至不编译: (field - types) 是二进制表达式,但它应该是第 13 行第 20 行的变量表达式
【问题讨论】:
-
这看起来很麻烦。为什么不试试 XMLSlurper。它更加 Groovy!