可以使用静态类型的Groovy ++进行XML处理吗?
示例(用于测试,您可以使用Groovy++ web console):
@Typed package test
def CAR_RECORDS = '''
<records>
<car name='HSV Maloo' make='Holden' year='2006'>
<country>Australia</country>
<record type='speed'>Production Pickup Truck with speed of 271kph</record>
</car>
</records>
'''
def records = new XmlSlurper().parseText(CAR_RECORDS)
println records.car
结果:
startup failed:
Script1.groovy: 14: Cannot find property car of class GPathResult
@ line 14, column 9.
records.car
^
1 error
答案 0 :(得分:1)
看起来不像......你可以使用:
@Typed(TypePolicy.MIXED)
然后
println records.car
有效,但您无法通过以下方式获取属性值:
println records.car.@name
然后你得到错误:
Cannot find field name of class Object
我猜XmlSlurping目前对于groovy ++来说太过动态了