Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
Closes a gap in GPathResult methods by providing a new "getBody()" method.
The method extracts the complete body of an XML tag into a closure wich can
then be inserted at another location in the XML builder.
The example below demonstrates how to use the getBody() method.
In this example the <sec> tag is replaced by a <t> tag.
Then the body of the <sec> tag is inserted into the <t> tag.
The expected result is: <doc><t>Hello<p>World</p></t></doc>
Existing methods of GPathResult ignore CDATA. In the example below
the "Hello" would be ignored.
def xmlOut = new StreamingMarkupBuilder()
def xmlInStr ="""
<doc><sec>Hello<p>World</p></sec></doc>
"""
GPathResult xmlIn = new XmlSlurper().parseText(xmlInStr)
xmlIn.sec.replaceNode{ node ->
t()
}
println xmlOut.bind
{ mkp.yield xmlIn }