public class XMLWriter extends Object
Modifier and Type | Field and Description |
---|---|
protected boolean |
canonical
Canonical output.
|
protected static org.slf4j.Logger |
log |
protected PrintWriter |
out
Print writer.
|
Constructor and Description |
---|
XMLWriter(OutputStream outStream)
Constructor
|
XMLWriter(OutputStream outStream,
String charsetEncoding)
Creates a XML Writer object.
|
XMLWriter(Writer writer,
String charsetEncoding)
Creates a XML Writer object.
|
Modifier and Type | Method and Description |
---|---|
static void |
debug(Document doc)
Prints out the DOM-Tree on System.out for debugging purposes.
|
static void |
debugToFile(Document doc,
String filename)
Prints out the DOM-Tree to a file for debugging purposes.
|
protected String |
normalize(String s)
Converts a string to valid XML-Syntax replacing XML entities.
|
static String |
normalize(String s,
boolean canonical) |
void |
print(Document doc)
Prints the specified document.
|
void |
print(Document doc,
String styleSheet)
Prints the specified document.
|
int |
print(Node node,
int level)
Prints the specified node recursively
|
static void |
saveAsFile(Document doc,
String filename)
Saves an XML-Document as file.
|
static void |
setXmlWriterDebugPath(String path) |
protected Attr[] |
sortAttributes(NamedNodeMap attrs)
Sorts attributes by name.
|
protected static final org.slf4j.Logger log
protected PrintWriter out
protected boolean canonical
public XMLWriter(Writer writer, String charsetEncoding)
writer
- a writer to the output streamcharsetEncoding
- encoding type (i.e. utf-8)public XMLWriter(OutputStream outStream, String charsetEncoding) throws UnsupportedEncodingException
outStream
- the output streamcharsetEncoding
- The name of a supported
charset
UnsupportedEncodingException
- If the named encoding is not supportedpublic XMLWriter(OutputStream outStream)
outStream
- the output streampublic static void debug(Document doc)
doc
- The XML-Document to printpublic static void debugToFile(Document doc, String filename)
doc
- The XML-Document to printfilename
- The name of the file to write the XML-Document topublic static void saveAsFile(Document doc, String filename)
doc
- The XML-Document to printfilename
- The name of the file to write the XML-Document toFileWriteException
public static void setXmlWriterDebugPath(String path)
public int print(Node node, int level)
node
- the current node to printlevel
- the nesting level used for indenting the outputpublic void print(Document doc)
doc
- the XML-DOM-Document to printpublic void print(Document doc, String styleSheet)
doc
- the XML-DOM-Document to printstyleSheet
- the XML-DOM-Document to printprotected Attr[] sortAttributes(NamedNodeMap attrs)
attrs
- the unsorted list of attributesprotected String normalize(String s)
s
- the string to normalizeCopyright © 2008–2023 Apache Software Foundation. All rights reserved.