Package org.apache.groovy.xml.extensions

# Class XmlExtensions

java.lang.Object
org.apache.groovy.xml.extensions.XmlExtensions

public class XmlExtensions extends Object
This class defines all the new XML-related groovy methods which enhance the normal JDK XML classes when inside the Groovy environment. Static methods are used with the first parameter the destination class.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `XmlExtensions()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> T`
  `asType(Node self, Class<T> type)`
  Enables `node as Type` coercion for XML Nodes.
  `static Iterator<Node>`
  `iterator(NodeList nodeList)`
  Makes NodeList iterable by returning a read-only Iterator which traverses over each Node.
  `static String`
  `serialize(Element element)`
  Transforms the element to its text equivalent.

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

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

- ## Constructor Details

  - ### XmlExtensions

    public XmlExtensions()

- ## Method Details

  - ### iterator

    public static Iterator<Node> iterator(NodeList nodeList)
    Makes NodeList iterable by returning a read-only Iterator which traverses over each Node.
    Parameters:
      `nodeList` - a NodeList
    Returns:
      an Iterator for a NodeList
    Since:
      1.0

  - ### serialize

    public static String serialize(Element element)
    Transforms the element to its text equivalent. (The resulting string does not contain a xml declaration. Use `XmlUtil.serialize(element)` if you need the declaration.)
    Parameters:
      `element` - the element to serialize
    Returns:
      the string representation of the element
    Since:
      2.1

  - ### asType

    public static <T> T asType(Node self, Class<T> type)
    Enables `node as Type` coercion for XML Nodes. Converts the Node to a Map via `Node.toMap()` and then uses Groovy's standard Map coercion to produce the typed object. Does not require Jackson on the classpath.
    Type Parameters:
      `T` - the target type
    Parameters:
      `self` - the Node to convert
      `type` - the target type
    Returns:
      a typed object
    Since:
      6.0.0