groovy

Add a Utility Method for Converting GPathResults to XML

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-4
  • Fix Version/s: 1.7.2, 1.8-beta-1
  • Component/s: XML Processing
  • Labels:
    None
  • Number of attachments :
    0

Description

At the moment to output a GPathResult as XML you have to use the below syntax in StreamingMarkupBuilder:

System.out << new StreamingMarkupBuilder().bind {xml -> xml.mkp.yield myNode}

It is not clear what this is trying to achieve and to compound the problem the syntax differs between groovy scripts and classes. It would be better if there was a utility method to do this with a signature whose purpose is clear.

Activity

Hide
Claus Ibsen added a comment -

Great idea

Show
Claus Ibsen added a comment - Great idea
Hide
Paul King added a comment -

There are now some additional utility methods which may help. Firstly StreamingMarkupBuilder has a bindNode method.
For the example above you can go:

println new StreamingMarkupBuilder().bindNode(myNode).toString()

The builder.bindNode(node) method is just a shorthand for:

builder.bind{ out << node }

Also, XmlUtil now has serialize methods for {{GPathResult}}s. So you can pretty print the nodes as well.

Do these methods satisfy the requirement of this issue?

Show
Paul King added a comment - There are now some additional utility methods which may help. Firstly StreamingMarkupBuilder has a bindNode method. For the example above you can go:
println new StreamingMarkupBuilder().bindNode(myNode).toString()
The builder.bindNode(node) method is just a shorthand for:
builder.bind{ out << node }
Also, XmlUtil now has serialize methods for {{GPathResult}}s. So you can pretty print the nodes as well. Do these methods satisfy the requirement of this issue?
Hide
Paul King added a comment -

No further feedback. Assuming provided new methods satisfy this requirement.

Show
Paul King added a comment - No further feedback. Assuming provided new methods satisfy this requirement.
Hide
Anders Norgaard added a comment -

Lovely. Thanks a lot.

Show
Anders Norgaard added a comment - Lovely. Thanks a lot.

People

Vote (4)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: