|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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>
Nested Class Summary | |
---|---|
protected class |
XmlNodePrinter.NamespaceContext
|
Field Summary | |
---|---|
protected IndentPrinter |
out
|
Constructor Summary | |
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)
|
|
XmlNodePrinter(IndentPrinter out)
|
|
XmlNodePrinter(IndentPrinter out, java.lang.String quote)
|
|
XmlNodePrinter()
|
Method Summary | |
---|---|
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 |
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 | |
---|---|
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Field Detail |
---|
protected final IndentPrinter out
Constructor Detail |
---|
public XmlNodePrinter(java.io.PrintWriter out)
public XmlNodePrinter(java.io.PrintWriter out, java.lang.String indent)
public XmlNodePrinter(java.io.PrintWriter out, java.lang.String indent, java.lang.String quote)
public XmlNodePrinter(IndentPrinter out)
public XmlNodePrinter(IndentPrinter out, java.lang.String quote)
public XmlNodePrinter()
Method Detail |
---|
public java.lang.String getQuote()
public boolean isExpandEmptyElements()
true
, if empty elements will be represented by an opening tag
followed immediately by a closing tag.
public boolean isNamespaceAware()
true
.
public boolean isPreserveWhitespace()
false
.
public 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)
public void setExpandEmptyElements(boolean expandEmptyElements)
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)
namespaceAware
- the new desired value
public void setPreserveWhitespace(boolean preserveWhitespace)
preserveWhitespace
- the new desired value
public void setQuote(java.lang.String quote)
quote
- the quote character
Groovy Documentation