groovy

GPath: allow attribute reference using unquoted selectors in XmlParser Nodes, making it consistent with XmlSlurper

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.1-rc-2
  • Component/s: None
  • Labels:
    None
  • Environment:
    groovy 1.1 rc-1
  • Number of attachments :
    0

Description

The suggested way to access XML attributes from the results produced by XmlParser is to use the form x.'@attrName' . Note the quotes around the attribute name.

For XmlSlurper style of GPath, you can leave off the quotes, and write x.@attrName

This doesn't appear to be supported in the XmlParse style. The Groovy in Action book has a table (Table 12.4) on page 410-411, which shows
these variations and restrictions.

The form "x.@name" is also used, in general, in Groovy, to specify direct field access, see Groovy in Action on page 203, section titled
"Field access with .@".

Somehow, it appears, that for XmlSlurper results, you can use the ".@name" form to access an attribute.

It would be nice if the ".@name" form (where you don't have to "quote" the @name) worked also for XmlParse result "Nodes".

Activity

Hide
Guillaume Laforge added a comment -

Paul, if you fancy it, otherwise, feel free to un-assign it.

Show
Guillaume Laforge added a comment - Paul, if you fancy it, otherwise, feel free to un-assign it.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: