Package groovy.xml

# Class SAXBuilder

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

All Implemented Interfaces:
  `GroovyObject`

public class SAXBuilder extends BuilderSupport
A builder for generating W3C SAX events. Use similar to MarkupBuilder.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SAXBuilder(ContentHandler handler)`
  Creates a builder that forwards markup events to the supplied SAX content handler.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Object`
  `createNode(Object name)`
  Builder lifecycle callback that starts an element with no attributes or body text.
  `protected Object`
  `createNode(Object name, Object value)`
  Builder lifecycle callback that starts an element and immediately emits text content.
  `protected Object`
  `createNode(Object name, Map attributes)`
  Builder lifecycle callback that starts an element and emits attributes without body text.
  `protected Object`
  `createNode(Object name, Map attributeMap, Object text)`
  Builder lifecycle callback that starts an element, emits attributes and optionally emits text content.
  `protected void`
  `doStartElement(Object name, Attributes attributes)`
  Emits a SAX `startElement` event for the supplied node name.
  `protected void`
  `handleException(SAXException e)`
  Handles checked `SAXException`s raised while emitting SAX events.
  `protected void`
  `nodeCompleted(Object parent, Object name)`
  Builder lifecycle callback invoked when the current node is complete.
  `protected void`
  `setParent(Object parent, Object child)`
  Builder lifecycle callback invoked after a child node has been created.

  ### Methods inherited from class groovy.util.BuilderSupport

  `doInvokeMethod, getCurrent, getName, invokeMethod, invokeMethod, postNodeCompletion, setClosureDelegate, setCurrent`

  ### Methods inherited from class groovy.lang.GroovyObjectSupport

  `getMetaClass, setMetaClass`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface groovy.lang.GroovyObject

  `getProperty, setProperty`

- ## Constructor Details

  - ### SAXBuilder

    public SAXBuilder(ContentHandler handler)
    Creates a builder that forwards markup events to the supplied SAX content handler.
    Parameters:
      `handler` - the content handler receiving generated SAX events

- ## Method Details

  - ### setParent

    protected void setParent(Object parent, Object child)
    Builder lifecycle callback invoked after a child node has been created. This implementation is a no-op because parent relationships are expressed through SAX events.
    Specified by:
      `setParent` in class `BuilderSupport`
    Parameters:
      `parent` - the parent node marker
      `child` - the child node marker

  - ### createNode

    protected Object createNode(Object name)
    Builder lifecycle callback that starts an element with no attributes or body text.
    Specified by:
      `createNode` in class `BuilderSupport`
    Parameters:
      `name` - the node name
    Returns:
      the node marker used for subsequent callbacks

  - ### createNode

    protected Object createNode(Object name, Object value)
    Builder lifecycle callback that starts an element and immediately emits text content.
    Specified by:
      `createNode` in class `BuilderSupport`
    Parameters:
      `name` - the node name
      `value` - the text content to emit
    Returns:
      the node marker used for subsequent callbacks

  - ### createNode

    protected Object createNode(Object name, Map attributeMap, Object text)
    Builder lifecycle callback that starts an element, emits attributes and optionally emits text content.
    Specified by:
      `createNode` in class `BuilderSupport`
    Parameters:
      `name` - the node name
      `attributeMap` - the attributes to expose through the SAX event
      `text` - the optional text content to emit after the start element
    Returns:
      the node marker used for subsequent callbacks

  - ### doStartElement

    protected void doStartElement(Object name, Attributes attributes)
    Emits a SAX `startElement` event for the supplied node name. Subclasses may override to customize how start-element events are generated.
    Parameters:
      `name` - the node name
      `attributes` - the attributes to include with the start-element event

  - ### nodeCompleted

    protected void nodeCompleted(Object parent, Object name)
    Builder lifecycle callback invoked when the current node is complete.
    Overrides:
      `nodeCompleted` in class `BuilderSupport`
    Parameters:
      `parent` - the parent node marker
      `name` - the completed node name

  - ### handleException

    protected void handleException(SAXException e)
    Handles checked `SAXException`s raised while emitting SAX events. Subclasses may override to translate them differently.
    Parameters:
      `e` - the SAX exception to handle
    Throws:
      `RuntimeException` - by default, wrapping `e`

  - ### createNode

    protected Object createNode(Object name, Map attributes)
    Builder lifecycle callback that starts an element and emits attributes without body text.
    Specified by:
      `createNode` in class `BuilderSupport`
    Parameters:
      `name` - the node name
      `attributes` - the attributes to expose through the SAX event
    Returns:
      the node marker used for subsequent callbacks