Package groovy.xml
Class XmlNodePrinter
java.lang.Object
groovy.xml.XmlNodePrinter
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:
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionXmlNodePrinter
(IndentPrinter out, String quote) XmlNodePrinter
(PrintWriter out, String indent) XmlNodePrinter
(PrintWriter out, String indent, String quote) -
Method Summary
Modifier and TypeMethodDescriptiongetQuote()
Get Quote to use when printing attributes.boolean
Whether empty elements are expanded from <tagName/> to <tagName></tagName>.boolean
Check if namespace handling is enabled.boolean
Check if whitespace preservation is enabled.void
protected void
print
(Node node, XmlNodePrinter.NamespaceContext ctx) protected void
protected void
protected void
printLineEnd
(String comment) protected void
printList
(List list, XmlNodePrinter.NamespaceContext ctx) protected void
printName
(Node node, XmlNodePrinter.NamespaceContext ctx, boolean begin, boolean preserve) protected void
printNameAttributes
(Map attributes, XmlNodePrinter.NamespaceContext ctx) protected void
printNamespace
(Object object, XmlNodePrinter.NamespaceContext ctx) protected void
printSimpleItem
(Object value) protected boolean
printSpecialNode
(Node node) void
setExpandEmptyElements
(boolean expandEmptyElements) Whether empty elements are expanded from <tagName/> to <tagName></tagName>.void
setNamespaceAware
(boolean namespaceAware) Enable and/or disable namespace handling.void
setPreserveWhitespace
(boolean preserveWhitespace) Enable and/or disable preservation of whitespace.void
Set Quote to use when printing attributes.
-
Field Details
-
out
-
-
Constructor Details
-
XmlNodePrinter
-
XmlNodePrinter
-
XmlNodePrinter
-
XmlNodePrinter
-
XmlNodePrinter
-
XmlNodePrinter
public XmlNodePrinter()
-
-
Method Details
-
print
-
isNamespaceAware
public boolean isNamespaceAware()Check if namespace handling is enabled. Defaults totrue
.- 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 tofalse
.- 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
Get Quote to use when printing attributes.- Returns:
- the quote character
-
setQuote
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 <tagName/> to <tagName></tagName>.- Parameters:
expandEmptyElements
- iftrue
, empty elements will be represented by an opening tag followed immediately by a closing tag. Defaults tofalse
.
-
print
-
printLineBegin
protected void printLineBegin() -
printLineEnd
protected void printLineEnd() -
printLineEnd
-
printList
-
printSimpleItem
-
printName
protected void printName(Node node, XmlNodePrinter.NamespaceContext ctx, boolean begin, boolean preserve) -
printSpecialNode
-
printNamespace
-
printNameAttributes
-