Groovy web console

subscribe to the feed Subscribe
to this
site
Replace & in XML (via #groovywebconsole)
tweet this snippet Tweet
this
script

Replace & in XML

Published 3 months ago by Elmar Pitschke with tags XML
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def xml = """<PageMap><DataObject type="document"><Attribute name='country'>de & en</Attribute></DataObject></PageMap>"""

def data = new XmlSlurper().parseText(xml.replaceAll( /&(?!(quot|apos|lt|gt|amp);)/ ) { m -> "&" }) 

println data.DataObject.Attribute.text()