markupbuilder

Can I just hand groovy's markupbuilder a node list?

I'm doing some XML processing with groovy. Specifically, I'm inhaling an XML file via XMLParser, doing a whole batch of in-memory processing, and then serializing the resulting data back out to XML via a MarkupBuiler. The vast majority of the data in the file gets transferred to a non-xml based object hierarchy to talk to the gui and h...

How to convert XML file in UTF-8 using Groovy builder StreamingMarkupBuilder

Hi, Even if the question subject seems complicated, the issue is quite simple. I create an XML file with the following script: def xmlFile = new File("file-${System.currentTimeMillis()}.xml") mb = new groovy.xml.StreamingMarkupBuilder() mb.encoding = "UTF-8" new FileWriter(exportXmlFile) << mb.bind { mkp.xmlDeclaration() out <...

Create groovy xml with an "envelop" - add nodes in the middle of a xml structure

Hi all, (sorry for the weird title...) I want to use the groovy builder system to create a xml. My problem is that i want to have some kind of envelop around, which the user dont has to care about. An example: def builder = new groovy.xml.MarkupBuilder() builder.foo() { bar('hello') } this should create lets say <Something i...

Remove newlines from MarkupBuilder result

Is there a way to control groovy's MarkupBuilder's output and filter out the newline characters? I have code like below: import groovy.xml.MarkupBuilder def writer = new StringWriter() def xml = new MarkupBuilder(writer) xml.basket(){ fruit (type:"apple", 1) fruit (type:"orange", 2) } which invariably outputs: <basket>...

replace XmlSlurper tag with arbitrary XML

Dear All: I am trying to replace specific XmlSlurper tags with arbitrary XML strings. The best way I have managed to come up with to do this is: #!/usr/bin/env groovy import groovy.xml.StreamingMarkupBuilder def page=new XmlSlurper(new org.cyberneko.html.parsers.SAXParser()).parseText(""" <html> <head></head> <body> <one attr1='val1'...

Use of Namespaces in Groovy MarkupBuilder

I want have the following output: <?xml version="1.0" encoding="UTF-8"?> <structure:structuralDataRoot xmlns:register="http://www.test.ch/register/1" xmlns:structure="http://test.ch/structure/1" > <structure:tester>ZH</structure:tester> <structure:surveyYear>2001</structure:surveyYear> <structure:surfaceData> <structure:houseS...

Detecting first and last item inside a Groovy each{} closure

I am using Groovy's handy MarkupBuilder to build an HTML page from various source data. One thing I am struggling to do nicely is build an HTML table and apply different style classes to the first and last rows. This is probably best illustrated with an example... table() { thead() { tr(){ th('class':'l name', 'name') ...

How can I insert an xml comment with Groovy MarkupBuilder?

I would like to insert comments into my xml document with a Groovy MarkupBuilder. How is it possible? ...