Groovy Documentation

## groovy.xml
[Groovy] Class StaxBuilder

    java.lang.Object
      groovy.lang.GroovyObjectSupport
          groovy.util.BuilderSupport
              groovy.xml.StaxBuilder

    class StaxBuilder
    extends BuilderSupport

A Groovy builder that works with Stax processors. Using Java 6, typical usage is as follows:

     def factory = XMLOutputFactory.newInstance()
     def writer = new StringWriter()
     def builder = new StaxBuilder(factory.createXMLStreamWriter(writer))
     builder.root1(a:5, b:7) {
         elem1('hello1')
         elem2('hello2')
         elem3(x:7)
     }
     assert writer == """<elem1>hello1</elem1><elem2>hello2</elem2>"""

Or an external library such as Jettison can be used as follows:

     @Grab('org.codehaus.jettison:jettison:1.2')
     import org.codehaus.jettison.mapped.*
     import javax.xml.stream.XMLStreamException

     def conv = new MappedNamespaceConvention()
     def writer = new StringWriter()
     def mappedWriter = new MappedXMLStreamWriter(conv, writer)
     def builder = new groovy.xml.StaxBuilder(mappedWriter)
     builder.root1(a:5, b:7) {
         elem1('hello1')
         elem2('hello2')
         elem3(x:7)
     }
     assert writer.toString() == '''{"root1":{"@a":"5","@b":"7","elem1":"hello1","elem2":"hello2","elem3":{"@x":"7"}}}'''

Authors:
  Dejan Bosanac
  Paul King

Property Summary
`java.lang.Object` | `writer`

Constructor Summary
`StaxBuilder(java.lang.Object xmlStreamWriter)`

Method Summary
`protected java.lang.Object` | `createNode(java.lang.Object name)`
`protected java.lang.Object` | `createNode(java.lang.Object name, java.lang.Object value)`
`protected java.lang.Object` | `createNode(java.lang.Object name, java.util.Map attributes)`
`protected java.lang.Object` | `createNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)`
`protected void` | `nodeCompleted(java.lang.Object parent, java.lang.Object node)`
`protected void` | `setParent(java.lang.Object parent, java.lang.Object child)`

Methods inherited from class BuilderSupport
createNode, createNode, createNode, createNode, doInvokeMethod, getCurrent, getName, invokeMethod, invokeMethod, nodeCompleted, postNodeCompletion, setClosureDelegate, setCurrent, setParent

Methods inherited from class GroovyObjectSupport
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Property Detail

### writer

    java.lang.Object writer

Constructor Detail

### StaxBuilder

    StaxBuilder(java.lang.Object xmlStreamWriter)

Method Detail

### createNode

    protected java.lang.Object createNode(java.lang.Object name)

### createNode

    protected java.lang.Object createNode(java.lang.Object name, java.lang.Object value)

### createNode

    protected java.lang.Object createNode(java.lang.Object name, java.util.Map attributes)

### createNode

    protected java.lang.Object createNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)

### nodeCompleted

    protected void nodeCompleted(java.lang.Object parent, java.lang.Object node)

### setParent

    protected void setParent(java.lang.Object parent, java.lang.Object child)

Groovy Documentation