boiling memoir

journey of one man

Convert GPathResult to String Without Tag0

In Groovy, you can use the follow code to convert node to XML String.

groovy.xml.XmlUtil.serialize(GPathResult node)

But sometimes the XML you end up with contains tag0 namespace all over
the elements. It happens because the doc contains default namespace
with empty prefix, so groovy uses a default prefix which is “tag0”.
The XML is still correct but it would be nice to not have to see that
crap. To do so you need to create a new closure with the node and
explicitly declare an empty string namespace. Then use
StreamingMarkupBuilder to convert the newly created closure to String.
The following code is how you would implement that logic.