Package groovy.util

Class 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):
    See Also:
    NodePrinter, XmlUtil.serialize(Node)
    • Constructor Detail

      • XmlNodePrinter

        public XmlNodePrinter​( out)
      • XmlNodePrinter

        public XmlNodePrinter​( out,
                              java.lang.String indent)
      • XmlNodePrinter

        public XmlNodePrinter​( out,
                              java.lang.String indent,
                              java.lang.String quote)
      • 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.
        true if namespace handling is enabled
      • setNamespaceAware

        public void setNamespaceAware​(boolean namespaceAware)
        Enable and/or disable namespace handling.
        namespaceAware - the new desired value
      • isPreserveWhitespace

        public boolean isPreserveWhitespace()
        Check if whitespace preservation is enabled. Defaults to false.
        true if whitespaces are honoured when printing simple text nodes
      • setPreserveWhitespace

        public void setPreserveWhitespace​(boolean preserveWhitespace)
        Enable and/or disable preservation of whitespace.
        preserveWhitespace - the new desired value
      • getQuote

        public java.lang.String getQuote()
        Get Quote to use when printing attributes.
        the quote character
      • setQuote

        public void setQuote​(java.lang.String quote)
        Set Quote to use when printing attributes.
        quote - the quote character
      • isExpandEmptyElements

        public boolean isExpandEmptyElements()
        Whether empty elements are expanded from <tagName/> to <tagName></tagName>.
        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 <tagName/> to <tagName></tagName>.
        expandEmptyElements - if true, empty elements will be represented by an opening tag followed immediately by a closing tag. Defaults to false.
      • printLineBegin

        protected void printLineBegin()
      • printLineEnd

        protected void printLineEnd()
      • printLineEnd

        protected void printLineEnd​(java.lang.String comment)
      • printSimpleItem

        protected void printSimpleItem​(java.lang.Object value)
      • printSpecialNode

        protected boolean printSpecialNode​(Node node)