Class XmlPrinter
- java.lang.Object
-
- com.github.javaparser.printer.XmlPrinter
-
public class XmlPrinter extends Object
Outputs an XML file containing the AST meant for inspecting it.
-
-
Constructor Summary
Constructors Constructor Description XmlPrinter(boolean outputNodeType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method 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.
-
-
-
Method Detail
-
output
public String output(Node node)
Generate a xml string for given AST Node. Tag name of root element in the result document will be "root".- Parameters:
node
- AST node to be converted to XML- Returns:
- XML document corresponding to node
-
output
@Deprecated public void output(Node node, String name, int level, StringBuilder builder)
Deprecated.Output XML data from an AST node to a String Builder. This method is kept for backward compatilibity only and should be removed in future releases.- Parameters:
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 XML
-
stringWriterOutput
public StringWriter stringWriterOutput(Node node, String name)
Create a string writer filled with XML document representing an AST node.Returned stringWriter is not closed upon return because doing so
has no effect
. So users of this method are not required to close it.- Parameters:
node
- AST node to be converted to XMLname
- Tag name of root element in the resulting document- Returns:
- Stringwriter filled with XML document
- Throws:
com.github.javaparser.printer.RuntimeXMLStreamException
- Unchecked exception wrapping checkedXMLStreamException
, when any error on producing XML output occours
-
outputDocument
public void outputDocument(Node node, String name, Writer writer) throws XMLStreamException
Output the XML Document representing given AST node to given writer.This method creates a
XMLStreamWriter
that writes to given writer and delegates execution tooutputDocument(Node, String, XMLStreamWriter)
Provided writer is NOT closed at the end of execution of this method.
- Parameters:
node
- AST node to be converted to XMLname
- Tag name of root element of documentwriter
- Target to get the document writen to- Throws:
XMLStreamException
- When any error on outputting XML occours
-
outputDocument
public void outputDocument(Node node, String name, XMLStreamWriter xmlWriter) throws XMLStreamException
Output the XML Document representing an AST node to given XMLStreamWriter.This method outputs the starting of XML document, then delegates to
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.
- Parameters:
node
- AST node to be converted to XMLname
- Tag name of root element of documentxmlWriter
- Target to get document written to- Throws:
XMLStreamException
- When any error on outputting XML occours- See Also:
outputNode(String, Node, XMLStreamWriter)
-
outputNode
public void outputNode(Node node, String name, XMLStreamWriter xmlWriter) throws XMLStreamException
Output the XML Element representing an AST node to given writer.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.
- Parameters:
node
- AST node to be converted to XMLname
- Tag name of element corresponding to nodexmlWriter
- Target to get XML written to- Throws:
XMLStreamException
- When any error on outputting XML occours- See Also:
outputDocument(String, Node, XMLStreamWriter)
-
print
public static void print(Node node)
-
-