开发者

Groovy++ and XML

Can be used statically typed Groovy++ for XML processing?

Example (for testing you can use Groovy++ web console):

@Ty开发者_JAVA百科ped 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


Doesn't look like it... You can use:

@Typed(TypePolicy.MIXED)

and then

println records.car

works, but you cannot get to attribute values via:

println records.car.@name

As you then get the error:

Cannot find field name of class Object

I guess XmlSlurping is currently a bit too dynamic for groovy++

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜