Package groovy.xml
Class XmlNodePrinter
java.lang.Object
groovy.xml.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 SummaryNested Classes Modifier and Type Class Description protected static classXmlNodePrinter.NamespaceContext
- 
Field SummaryFields Modifier and Type Field Description protected IndentPrinterout
- 
Constructor SummaryConstructors Constructor 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 SummaryModifier and Type Method Description protected java.lang.StringgetName(java.lang.Object object)java.lang.StringgetQuote()Get Quote to use when printing attributes.booleanisExpandEmptyElements()Whether empty elements are expanded from <tagName/> to <tagName></tagName>.booleanisNamespaceAware()Check if namespace handling is enabled.booleanisPreserveWhitespace()Check if whitespace preservation is enabled.voidprint(Node node)protected voidprint(Node node, XmlNodePrinter.NamespaceContext ctx)protected voidprintLineBegin()protected voidprintLineEnd()protected voidprintLineEnd(java.lang.String comment)protected voidprintList(java.util.List list, XmlNodePrinter.NamespaceContext ctx)protected voidprintName(Node node, XmlNodePrinter.NamespaceContext ctx, boolean begin, boolean preserve)protected voidprintNameAttributes(java.util.Map attributes, XmlNodePrinter.NamespaceContext ctx)protected voidprintNamespace(java.lang.Object object, XmlNodePrinter.NamespaceContext ctx)protected voidprintSimpleItem(java.lang.Object value)protected booleanprintSpecialNode(Node node)voidsetExpandEmptyElements(boolean expandEmptyElements)Whether empty elements are expanded from <tagName/> to <tagName></tagName>.voidsetNamespaceAware(boolean namespaceAware)Enable and/or disable namespace handling.voidsetPreserveWhitespace(boolean preserveWhitespace)Enable and/or disable preservation of whitespace.voidsetQuote(java.lang.String quote)Set Quote to use when printing attributes.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
- 
Field Details- 
out
 
- 
- 
Constructor Details- 
XmlNodePrinterpublic XmlNodePrinter(java.io.PrintWriter out)
- 
XmlNodePrinterpublic XmlNodePrinter(java.io.PrintWriter out, java.lang.String indent)
- 
XmlNodePrinterpublic XmlNodePrinter(java.io.PrintWriter out, java.lang.String indent, java.lang.String quote)
- 
XmlNodePrinter
- 
XmlNodePrinter
- 
XmlNodePrinterpublic XmlNodePrinter()
 
- 
- 
Method Details- 
print
- 
isNamespaceAwarepublic boolean isNamespaceAware()Check if namespace handling is enabled. Defaults totrue.- Returns:
- true if namespace handling is enabled
 
- 
setNamespaceAwarepublic void setNamespaceAware(boolean namespaceAware)Enable and/or disable namespace handling.- Parameters:
- namespaceAware- the new desired value
 
- 
isPreserveWhitespacepublic boolean isPreserveWhitespace()Check if whitespace preservation is enabled. Defaults tofalse.- Returns:
- true if whitespaces are honoured when printing simple text nodes
 
- 
setPreserveWhitespacepublic void setPreserveWhitespace(boolean preserveWhitespace)Enable and/or disable preservation of whitespace.- Parameters:
- preserveWhitespace- the new desired value
 
- 
getQuotepublic java.lang.String getQuote()Get Quote to use when printing attributes.- Returns:
- the quote character
 
- 
setQuotepublic void setQuote(java.lang.String quote)Set Quote to use when printing attributes.- Parameters:
- quote- the quote character
 
- 
isExpandEmptyElementspublic 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.
 
- 
setExpandEmptyElementspublic 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.
 
- 
print
- 
printLineBeginprotected void printLineBegin()
- 
printLineEndprotected void printLineEnd()
- 
printLineEndprotected void printLineEnd(java.lang.String comment)
- 
printList
- 
printSimpleItemprotected void printSimpleItem(java.lang.Object value)
- 
printNameprotected void printName(Node node, XmlNodePrinter.NamespaceContext ctx, boolean begin, boolean preserve)
- 
printSpecialNode
- 
printNamespace
- 
printNameAttributes
- 
getNameprotected java.lang.String getName(java.lang.Object object)
 
-