Package groovy.xml

Class SAXBuilder

All Implemented Interfaces:
GroovyObject

public class SAXBuilder extends BuilderSupport
A builder for generating W3C SAX events. Use similar to MarkupBuilder.
  • 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 SAXExceptions 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