Package: groovy.xml

## [Java] Class XmlNodePrinter

- groovy.xml.XmlNodePrinter

-     public class XmlNodePrinter
      extends 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

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `protected static class` | `XmlNodePrinter.NamespaceContext` |

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected IndentPrinter` | `out` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `XmlNodePrinter(PrintWriter out)`
    `XmlNodePrinter(PrintWriter out, String indent)`
    `XmlNodePrinter(PrintWriter out, String indent, String quote)`
    `XmlNodePrinter(IndentPrinter out)`
    `XmlNodePrinter(IndentPrinter out, String quote)`
    `XmlNodePrinter()`

  - ### Methods Summary

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

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Field Detail

    - #### protected final IndentPrinter out

  - ### Constructor Detail

    - #### public XmlNodePrinter(PrintWriter out)

    - #### public XmlNodePrinter(PrintWriter out, String indent)

    - #### public XmlNodePrinter(PrintWriter out, String indent, String quote)

    - #### public XmlNodePrinter(IndentPrinter out)

    - #### public XmlNodePrinter(IndentPrinter out, String quote)

    - #### public XmlNodePrinter()

  - ### Method Detail

    - #### protected String getName(Object object)

    - #### public String getQuote()

      Get Quote to use when printing attributes.

      Returns:
        the quote character

    - #### 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.

    - #### public boolean isNamespaceAware()

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

      Returns:
        true if namespace handling is enabled

    - #### public boolean isPreserveWhitespace()

      Check if whitespace preservation is enabled. Defaults to `false`.

      Returns:
        true if whitespaces are honoured when printing simple text nodes

    - #### public void print(Node node)

    - #### protected void print(Node node, NamespaceContext ctx)

    - #### protected void printLineBegin()

    - #### protected void printLineEnd()

    - #### protected void printLineEnd(String comment)

    - #### protected void printList(List list, NamespaceContext ctx)

    - #### protected void printName(Node node, NamespaceContext ctx, boolean begin, boolean preserve)

    - #### protected void printNameAttributes(Map attributes, NamespaceContext ctx)

    - #### protected void printNamespace(Object object, NamespaceContext ctx)

    - #### protected void printSimpleItem(Object value)

    - #### protected boolean printSpecialNode(Node node)

    - #### public void setExpandEmptyElements(boolean expandEmptyElements)

      Whether empty elements are expanded from <tagName/> to <tagName></tagName>.

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

    - #### public void setNamespaceAware(boolean namespaceAware)

      Enable and/or disable namespace handling.

      Parameters:
        `namespaceAware` - the new desired value

    - #### public void setPreserveWhitespace(boolean preserveWhitespace)

      Enable and/or disable preservation of whitespace.

      Parameters:
        `preserveWhitespace` - the new desired value

    - #### public void setQuote(String quote)

      Set Quote to use when printing attributes.

      Parameters:
        `quote` - the quote character