or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

dom-processing.mdindex.mdnamespace-support.mdxml-generation.mdxml-parsing.mdxml-utilities.md
tile.json

tessl/maven-org-apache-groovy--groovy-xml

Groovy XML support library providing comprehensive XML processing capabilities including parsing, manipulation, and generation of XML documents using Groovy's native XML handling features, XmlSlurper, and XmlParser APIs

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.apache.groovy/groovy-xml@5.0.x

To install, run

npx @tessl/cli install tessl/maven-org-apache-groovy--groovy-xml@5.0.0

index.mddocs/

Groovy XML

A comprehensive Groovy library for XML processing providing powerful and idiomatic APIs for parsing, generating, and manipulating XML documents. The library offers multiple processing approaches from simple parsing to advanced streaming operations, all designed to leverage Groovy's dynamic features for intuitive XML handling.

Package Information

  • Package Name: org.apache.groovy:groovy-xml
  • Package Type: maven
  • Language: Groovy/Java
  • Installation: Add to Gradle: implementation 'org.apache.groovy:groovy-xml:5.0.0'

Core Imports

import groovy.xml.*

Specific imports for common use cases:

import groovy.xml.XmlParser
import groovy.xml.XmlSlurper
import groovy.xml.MarkupBuilder
import groovy.xml.DOMBuilder
import groovy.xml.XmlUtil

Basic Usage

import groovy.xml.*

// Parse XML with XmlParser
def parser = new XmlParser()
def root = parser.parseText('''
    <books>
        <book id="1" title="Groovy in Action"/>
        <book id="2" title="Programming Groovy"/>
    </books>
''')

// Access parsed data
println root.book[0].@title  // "Groovy in Action"
println root.book.size()     // 2

// Generate XML with MarkupBuilder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.books {
    book(id: "1", title: "Groovy in Action")
    book(id: "2", title: "Programming Groovy")
}
println writer.toString()

// Parse with XmlSlurper for GPath navigation
def slurper = new XmlSlurper()
def doc = slurper.parseText('''<catalog><book price="12.99">Title</book></catalog>''')
println doc.book.@price      // "12.99"
println doc.book.text()      // "Title"

Architecture

The Groovy XML library is built around several key processing paradigms:

  • Tree-based Parsing: XmlParser creates mutable DOM-like trees using groovy.util.Node
  • GPath Navigation: XmlSlurper provides lazy-evaluated GPath expressions for XML traversal
  • Builder Pattern: Multiple builders (MarkupBuilder, DOMBuilder, StreamingMarkupBuilder) for XML generation
  • DOM Integration: Enhanced DOM processing with Groovy category methods
  • Streaming Support: Memory-efficient streaming builders for large XML documents
  • Namespace Awareness: Full XML namespace support across all processing modes

Capabilities

XML Parsing

Two primary parsing approaches: tree-based parsing with XmlParser for mutable document trees, and GPath-based parsing with XmlSlurper for lazy evaluation and XPath-like navigation.

class XmlParser {
    XmlParser()
    XmlParser(boolean validating, boolean namespaceAware)
    Node parse(File file)
    Node parse(String uri)
    Node parseText(String text)
}

class XmlSlurper {
    XmlSlurper()
    XmlSlurper(boolean validating, boolean namespaceAware)
    GPathResult parse(File file)
    GPathResult parse(String uri) 
    GPathResult parseText(String text)
}

XML Parsing

XML Generation

Comprehensive XML building capabilities including markup builders for formatted output, DOM builders for W3C DOM integration, and streaming builders for memory-efficient large document generation.

class MarkupBuilder {
    MarkupBuilder()
    MarkupBuilder(Writer writer)
    MarkupBuilderHelper getMkp()
}

class DOMBuilder {
    static DOMBuilder newInstance()
    Document parseText(String text)
}

class StreamingMarkupBuilder {
    def bind(Closure closure)
    def bindNode(Node node)
}

class Entity {
    Entity(String name)
    Entity(int code)
    // Comprehensive XML entity constants (nbsp, copy, lt, gt, etc.)
}

XML Generation

DOM Processing

Enhanced DOM processing with Groovy category methods providing GPath-style navigation and manipulation for standard W3C DOM objects.

class DOMCategory {
    static Object get(Element element, String elementName)
    static String text(Node node)
    static Element appendNode(Element self, Object name)
    static NodeList depthFirst(Element self)
    static String xpath(Node self, String expression)
}

DOM Processing

XML Utilities

Utility functions for XML serialization, pretty printing, escaping, and advanced parser configuration with schema validation support.

class XmlUtil {
    static String serialize(Element element)
    static String serialize(Node node)
    static String serialize(GPathResult node)
    static String escapeXml(String text)
    static SAXParser newSAXParser(String schemaLanguage, Source... schemas)
}

XML Utilities

Namespace Support

Comprehensive XML namespace support including namespace builders, QName factories, and namespace-aware parsing and generation across all processing modes.

class Namespace {
    Namespace(String uri)
    Namespace(String uri, String prefix)
    QName get(String localName)
}

class NamespaceBuilder {
    NamespaceBuilderSupport namespace(String uri)
    NamespaceBuilderSupport declareNamespace(Map ns)
}

Namespace Support

Types

// Core result types
class Node {
    String name()
    Object value()
    List children()
    Map attributes()
    Node parent()
}

abstract class GPathResult {
    String name()
    String text()
    int size()
    boolean isEmpty()
    GPathResult parent()
    Iterator iterator()
}

// Builder helper types
class MarkupBuilderHelper {
    void yield(Object value)
    void comment(String value)
    void xmlDeclaration(Map<String, Object> args)
}

// Exception types
class SAXException extends Exception
class ParserConfigurationException extends Exception