public class XmlPrinter extends Object
Constructor and Description |
---|
XmlPrinter(boolean outputNodeType) |
Modifier and Type | Method and Description |
---|---|
String |
output(Node node)
Generate a xml string for given AST Node.
|
void |
output(Node node,
String name,
int level,
StringBuilder builder)
Deprecated.
|
void |
outputDocument(Node node,
String name,
Writer writer)
Output the XML Document representing given AST node to given writer.
|
void |
outputDocument(Node node,
String name,
XMLStreamWriter xmlWriter)
Output the XML Document representing an AST node to given XMLStreamWriter.
|
void |
outputNode(Node node,
String name,
XMLStreamWriter xmlWriter)
Output the XML Element representing an AST node to given writer.
|
static void |
print(Node node) |
StringWriter |
stringWriterOutput(Node node,
String name)
Create a string writer filled with XML document representing an AST node.
|
public String output(Node node)
node
- AST node to be converted to XML@Deprecated public void output(Node node, String name, int level, StringBuilder builder)
node
- AST node to be converted to XMLname
- Tag name of root element in the resulting documentlevel
- Nesting level of node in tree. Not used.builder
- Target object to receive the generated XMLpublic StringWriter stringWriterOutput(Node node, String name)
Returned stringWriter is not closed upon return because doing so has no effect
.
So users of this method are not required to close it.
node
- AST node to be converted to XMLname
- Tag name of root element in the resulting documentcom.github.javaparser.printer.RuntimeXMLStreamException
- Unchecked exception wrapping checked XMLStreamException
, when any
error on producing XML output occourspublic void outputDocument(Node node, String name, Writer writer) throws XMLStreamException
This method creates a XMLStreamWriter
that writes to given writer and delegates execution to
outputDocument(Node, String, XMLStreamWriter)
Provided writer is NOT closed at the end of execution of this method.
node
- AST node to be converted to XMLname
- Tag name of root element of documentwriter
- Target to get the document writen toXMLStreamException
- When any error on outputting XML occourspublic void outputDocument(Node node, String name, XMLStreamWriter xmlWriter) throws XMLStreamException
This method outputs the starting of XML document, then delegates to #outputNode(Node, String, XMLStreamWriter) for writing the root element of XML document, and finally outputs the ending of XML document.
This method is used when the root element of an XML document corresponds to an AST node. Would an element corresponding to an AST node be written as child of another element, then {@link #outputNode(String, Node, XMLStreamWriter)} should be used instead. Actually, outputNode is used recursively for outputting nested elements from AST.
Provided xmlWriter is NOT closed at the end of execution of this method.
node
- AST node to be converted to XMLname
- Tag name of root element of documentxmlWriter
- Target to get document written toXMLStreamException
- When any error on outputting XML occoursoutputNode(String, Node, XMLStreamWriter)
public void outputNode(Node node, String name, XMLStreamWriter xmlWriter) throws XMLStreamException
This method outputs an XML Element with given tag name to writer. It is used recursively for generating nested elements corresponding to AST.
For generating a complete XML document from an AST node, outputDocument(String, Node, XMLStreamWriter)
should be used instead.
Provided xmlWriter is NOT closed at the end of execution of this method.
node
- AST node to be converted to XMLname
- Tag name of element corresponding to nodexmlWriter
- Target to get XML written toXMLStreamException
- When any error on outputting XML occoursoutputDocument(String, Node, XMLStreamWriter)
public static void print(Node node)
Copyright © 2007–2024. All rights reserved.