groovy.util

## Class XmlNodePrinter

- java.lang.Object
- - groovy.util.XmlNodePrinter

-     public class XmlNodePrinter
      extends java.lang.Object

  Prints a `groovy.util.Node` (as used with `XmlParser`) including all children in XML format. Typical usage:

       def xml = '<html><head><title>Title</title></head><body><h1>Header</h1></body></html>'
       def root = new XmlParser().parseText(xml)
       new XmlNodePrinter(preserveWhitespace:true).print(root.body[0])

  which when run produces this on stdout (or use your own `PrintWriter` to direct elsewhere):

       <body>
         <h1>Header</h1>
       </body>

  See Also:
    `NodePrinter`, `XmlUtil.serialize(Node)`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `XmlNodePrinter.NamespaceContext`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected IndentPrinter` | `out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XmlNodePrinter()`
    `XmlNodePrinter(IndentPrinter out)`
    `XmlNodePrinter(IndentPrinter out, java.lang.String quote)`
    `XmlNodePrinter(java.io.PrintWriter out)`
    `XmlNodePrinter(java.io.PrintWriter out, java.lang.String indent)`
    `XmlNodePrinter(java.io.PrintWriter out, java.lang.String indent, java.lang.String quote)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `getQuote()` Get Quote to use when printing attributes.
    `boolean` | `isExpandEmptyElements()` Whether empty elements are expanded from <tagName/> to <tagName></tagName>.
    `boolean` | `isNamespaceAware()` Check if namespace handling is enabled.
    `boolean` | `isPreserveWhitespace()` Check if whitespace preservation is enabled.
    `void` | `print(Node node)`
    `protected void` | `print(Node node, XmlNodePrinter.NamespaceContext ctx)`
    `protected void` | `printLineBegin()`
    `protected void` | `printLineEnd()`
    `protected void` | `printLineEnd(java.lang.String comment)`
    `protected void` | `printList(java.util.List list, XmlNodePrinter.NamespaceContext ctx)`
    `protected void` | `printName(Node node, XmlNodePrinter.NamespaceContext ctx, boolean begin, boolean preserve)`
    `protected void` | `printNameAttributes(java.util.Map attributes, XmlNodePrinter.NamespaceContext ctx)`
    `protected void` | `printNamespace(java.lang.Object object, XmlNodePrinter.NamespaceContext ctx)`
    `protected void` | `printSimpleItem(java.lang.Object value)`
    `protected boolean` | `printSpecialNode(Node node)`
    `void` | `setExpandEmptyElements(boolean expandEmptyElements)` Whether empty elements are expanded from to .
    `void` | `setNamespaceAware(boolean namespaceAware)` Enable and/or disable namespace handling.
    `void` | `setPreserveWhitespace(boolean preserveWhitespace)` Enable and/or disable preservation of whitespace.
    `void` | `setQuote(java.lang.String quote)` Set Quote to use when printing attributes.

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

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

- - ### Field Detail

    - #### out

          protected final IndentPrinter out

  - ### Constructor Detail

    - #### XmlNodePrinter

          public XmlNodePrinter(java.io.PrintWriter out)

    - #### XmlNodePrinter

          public XmlNodePrinter(java.io.PrintWriter out,
                        java.lang.String indent)

    - #### XmlNodePrinter

          public XmlNodePrinter(java.io.PrintWriter out,
                        java.lang.String indent,
                        java.lang.String quote)

    - #### XmlNodePrinter

          public XmlNodePrinter(IndentPrinter out)

    - #### XmlNodePrinter

          public XmlNodePrinter(IndentPrinter out,
                        java.lang.String quote)

    - #### XmlNodePrinter

          public XmlNodePrinter()

  - ### Method Detail

    - #### print

          public void print(Node node)

    - #### isNamespaceAware

          public boolean isNamespaceAware()

      Check if namespace handling is enabled. Defaults to `true`.
      Returns:
        true if namespace handling is enabled

    - #### setNamespaceAware

          public void setNamespaceAware(boolean namespaceAware)

      Enable and/or disable namespace handling.
      Parameters:
        `namespaceAware` - the new desired value

    - #### isPreserveWhitespace

          public boolean isPreserveWhitespace()

      Check if whitespace preservation is enabled. Defaults to `false`.
      Returns:
        true if whitespaces are honoured when printing simple text nodes

    - #### setPreserveWhitespace

          public void setPreserveWhitespace(boolean preserveWhitespace)

      Enable and/or disable preservation of whitespace.
      Parameters:
        `preserveWhitespace` - the new desired value

    - #### getQuote

          public java.lang.String getQuote()

      Get Quote to use when printing attributes.
      Returns:
        the quote character

    - #### setQuote

          public void setQuote(java.lang.String quote)

      Set Quote to use when printing attributes.
      Parameters:
        `quote` - the quote character

    - #### isExpandEmptyElements

          public boolean isExpandEmptyElements()

      Whether empty elements are expanded from <tagName/> to <tagName></tagName>.
      Returns:
        `true`, if empty elements will be represented by an opening tag followed immediately by a closing tag.

    - #### setExpandEmptyElements

          public void setExpandEmptyElements(boolean expandEmptyElements)

      Whether empty elements are expanded from to .
      Parameters:
        `expandEmptyElements` - if `true`, empty elements will be represented by an opening tag followed immediately by a closing tag. Defaults to `false`.

    - #### print

          protected void print(Node node,
                   XmlNodePrinter.NamespaceContext ctx)

    - #### printLineBegin

          protected void printLineBegin()

    - #### printLineEnd

          protected void printLineEnd()

    - #### printLineEnd

          protected void printLineEnd(java.lang.String comment)

    - #### printList

          protected void printList(java.util.List list,
                       XmlNodePrinter.NamespaceContext ctx)

    - #### printSimpleItem

          protected void printSimpleItem(java.lang.Object value)

    - #### printName

          protected void printName(Node node,
                       XmlNodePrinter.NamespaceContext ctx,
                       boolean begin,
                       boolean preserve)

    - #### printSpecialNode

          protected boolean printSpecialNode(Node node)

    - #### printNamespace

          protected void printNamespace(java.lang.Object object,
                            XmlNodePrinter.NamespaceContext ctx)

    - #### printNameAttributes

          protected void printNameAttributes(java.util.Map attributes,
                                 XmlNodePrinter.NamespaceContext ctx)