Groovy++和XML
可以使用静态类型的 Groovy++ 进行 XML 处理吗?
示例(为了进行测试,您可以使用 Groovy++ Web 控制台):
@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
Can be used statically typed Groovy++ for XML processing?
Example (for testing you can use 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
The result:
startup failed:
Script1.groovy: 14: Cannot find property car of class GPathResult
@ line 14, column 9.
records.car
^
1 error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来不像...您可以使用:
然后
工作,但是您无法通过以下方式获取属性值:
然后您会收到错误:
我猜 XmlSlurping 目前对于 groovy++ 来说有点过于动态
Doesn't look like it... You can use:
and then
works, but you cannot get to attribute values via:
As you then get the error:
I guess XmlSlurping is currently a bit too dynamic for groovy++