Class SaxXmlWriter

java.lang.Object
name.jurgenei.gradle.xml.SaxXmlWriter

public final class SaxXmlWriter extends Object
Minimal SAX XML writer with pretty-print output and helper methods for namespace-aware emission.
  • Method Details

    • createPretty

      public static SaxXmlWriter createPretty()
      Creates pretty-printing SAX writer with secure transformer defaults.
      Returns:
      initialized XML writer instance
    • startDocument

      public void startDocument() throws SAXException
      Starts XML document emission.
      Throws:
      SAXException - if downstream handler fails
    • endDocument

      public void endDocument() throws SAXException
      Completes XML document emission.
      Throws:
      SAXException - if downstream handler fails
    • startElement

      public void startElement(String namespaceUri, String localName, String qName, List<SaxXmlWriter.XmlAttribute> attributes, Map<String,String> namespaceMappings) throws SAXException
      Starts element with optional namespace declarations and attributes.
      Parameters:
      namespaceUri - namespace URI or empty string
      localName - local element name
      qName - qualified element name
      attributes - optional element attributes
      namespaceMappings - optional prefix to URI mappings declared on this element
      Throws:
      SAXException - if downstream handler fails
    • endElement

      public void endElement(String namespaceUri, String localName, String qName) throws SAXException
      Ends element and closes namespace declarations opened for it.
      Parameters:
      namespaceUri - namespace URI or empty string
      localName - local element name
      qName - qualified element name
      Throws:
      SAXException - if downstream handler fails
    • emptyElement

      public void emptyElement(String namespaceUri, String localName, String qName, List<SaxXmlWriter.XmlAttribute> attributes, Map<String,String> namespaceMappings) throws SAXException
      Emits empty element with optional attributes and namespace mappings.
      Parameters:
      namespaceUri - namespace URI or empty string
      localName - local element name
      qName - qualified element name
      attributes - optional element attributes
      namespaceMappings - optional prefix to URI mappings declared on this element
      Throws:
      SAXException - if downstream handler fails
    • text

      public void text(String text) throws SAXException
      Emits text node.
      Parameters:
      text - text content; blank values are ignored
      Throws:
      SAXException - if downstream handler fails
    • comment

      public void comment(String text) throws SAXException
      Emits XML comment.
      Parameters:
      text - comment text; blank values are ignored
      Throws:
      SAXException - if downstream handler fails
    • appendFragment

      public void appendFragment(String fragment, Map<String,String> namespaceHints)
      Parses and appends XML fragment under secure parser settings.
      Parameters:
      fragment - XML fragment to append
      namespaceHints - optional namespace hints used while wrapping fragment root
    • build

      public String build()
      Returns rendered XML output.
      Returns:
      serialized XML string
    • attr

      public static SaxXmlWriter.XmlAttribute attr(String name, String value)
      Creates non-namespaced attribute.
      Parameters:
      name - attribute name
      value - attribute value
      Returns:
      attribute descriptor
    • attr

      public static SaxXmlWriter.XmlAttribute attr(String namespaceUri, String localName, String qName, String value)
      Creates namespaced attribute.
      Parameters:
      namespaceUri - namespace URI or null
      localName - local name or null
      qName - qualified name
      value - attribute value
      Returns:
      attribute descriptor