I’m want to build a w3c xml node in groovy :
def CAR_RECORDS = '''<records>
<car name='HSV Maloo' make='Holden' year='2006'/>
<car name='P50' make='Peel' year='1962'/>
<car name='Royale' make='Bugatti' year='1931'/>
</records>
'''
def carRecords = new XmlParser().parseText(CAR_RECORDS)
but all I get using the MarkupBuilder is a groovy.util.Node ( carRecords is a groovy.util.Node ).
Is there an elegant way (that doesn’t require standard java xml coding) to do this?
What I’m looking for is something that will look like this:
def carRecords = new W3CXmlParser().parseText(CAR_RECORDS)
or anything of the kind…
Thanks!
The most simple way (pseudo code):
MarkupBuilderBackground: The W3C DOM API is very unfriendly from a Groovy point of view which is why the
MarkupBuilderuses its own type.Which is why Groovy supports the inverse operation: Convert W3C DOM nodes to
groovy.util.Nodes usingDomToGroovySee also: Creating XML using Groovy’s MarkupBuilder