Constructor and Description |
---|
XmlPrinter()
Create an XmlPrinter.
|
XmlPrinter(java.io.OutputStream os)
Creates a new XmlPrinter writing to an output stream.
|
XmlPrinter(java.io.Writer writer)
Creates a new XmlPrinter writing to a writer.
|
Modifier and Type | Method and Description |
---|---|
void |
addCdataElement(java.lang.String elt) |
void |
attribute(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
java.lang.String value)
Prints an attribute
|
void |
cdata(char[] buffer,
int offset,
int length) |
void |
cdata(java.lang.String text) |
void |
comment(java.lang.String data)
Prints a comment
|
void |
endDocument()
Callback when the document completes
|
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
Prints the end tag of an element
|
void |
endPrefixMapping(java.lang.String prefix) |
boolean |
finishAttributes()
Complete printing of the attributes when the open tag completes.
|
boolean |
getEscapeText()
Returns true if the text is currently being escaped
|
boolean |
getEscaping()
Returns the current XML escaping.
|
boolean |
getIncludeContentType()
Return true if the printer should automatically add the
<meta content-type> to HTML.
|
LineMap |
getLineMap() |
Path |
getPath() |
void |
init(WriteStream os)
Initialize the XmlPrinter with the write stream.
|
boolean |
isJSP()
True if this is JSP special cased.
|
boolean |
isPretty()
Returns true if the printer is currently pretty-printing the output.
|
void |
print(org.w3c.dom.Node node) |
static void |
print(Path path,
org.w3c.dom.Node node)
Prints the node as XML.
|
void |
printHeader(java.lang.String top)
Prints the header, if necessary.
|
void |
printHtml(org.w3c.dom.Node node)
Prints the node and children as HTML
|
void |
printNode(org.w3c.dom.Node node) |
void |
printPrettyXml(org.w3c.dom.Node node)
Prints the node and children as XML, automatically indending
|
java.lang.String |
printString(org.w3c.dom.Node node)
Prints the node as XML to a string.
|
void |
printXml(org.w3c.dom.Node node)
Prints the node as XML.
|
void |
processingInstruction(java.lang.String name,
java.lang.String data)
Prints a processing instruction
|
void |
setDocumentLocator(org.xml.sax.Locator locator)
Sets the locator.
|
void |
setEncoding(java.lang.String encoding)
Sets the character set encoding for the output file.
|
void |
setEscapeText(boolean isEscaped)
Sets true if the text should be escaped, else it will be printed
verbatim.
|
void |
setEscaping(boolean escapeText)
Sets to true if XML entities like < should be escaped as <.
|
void |
setIncludeContentType(boolean include)
Set true if the printer should automatically add the
<meta content-type> to HTML.
|
void |
setJSP(boolean isJsp)
Set true if this is JSP special cased.
|
void |
setLineMap(java.lang.String filename)
Creates a new line map.
|
void |
setLocation(java.lang.String filename,
int line,
int column)
Sets the current location.
|
void |
setMethod(java.lang.String method)
Sets the output methods, like the XSL <xsl:output method='method'/>.
|
void |
setMimeType(java.lang.String mimeType) |
void |
setPretty(boolean isPretty)
Set to true if the printer should add whitespace to 'pretty-print'
the output.
|
void |
setPrintDeclaration(boolean printDeclaration) |
void |
setPublicId(java.lang.String id) |
void |
setStandalone(java.lang.String standalone) |
void |
setSystemId(java.lang.String id) |
void |
setVersion(java.lang.String version)
Sets the XML/HTML version of the output file.
|
void |
startDocument()
Callback when the document starts printing.
|
void |
startDocument(org.w3c.dom.Document document) |
void |
startElement(java.lang.String url,
java.lang.String localName,
java.lang.String qName)
Called at the start of a new element.
|
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri) |
void |
text(char[] buffer,
int offset,
int length)
Prints text.
|
void |
text(java.lang.String text)
Prints text.
|
public XmlPrinter()
public XmlPrinter(java.io.OutputStream os)
os
- output stream serving as the destinationpublic XmlPrinter(java.io.Writer writer)
writer
- destination of the serialized nodepublic void init(WriteStream os)
os
- WriteStream containing the results.public static void print(Path path, org.w3c.dom.Node node) throws java.io.IOException
node
- source DOM nodejava.io.IOException
public void printXml(org.w3c.dom.Node node) throws java.io.IOException
node
- source DOM nodejava.io.IOException
public void printHtml(org.w3c.dom.Node node) throws java.io.IOException
node
- the top node to printjava.io.IOException
public void printPrettyXml(org.w3c.dom.Node node) throws java.io.IOException
node
- the top node to printjava.io.IOException
public java.lang.String printString(org.w3c.dom.Node node) throws java.io.IOException
node
- the source nodejava.io.IOException
public void setEscaping(boolean escapeText)
escapeText
- set to true if entities should be escaped.public boolean getEscaping()
public void setMethod(java.lang.String method)
public void setVersion(java.lang.String version)
version
- the output versionpublic void setEncoding(java.lang.String encoding)
encoding
- the mime name of the output encodingpublic void setMimeType(java.lang.String mimeType)
public void setJSP(boolean isJsp)
public boolean isJSP()
public void setPretty(boolean isPretty)
isPretty
- if true, add spaces for printingpublic boolean isPretty()
public void setPrintDeclaration(boolean printDeclaration)
public void setStandalone(java.lang.String standalone)
public void setSystemId(java.lang.String id)
public void setIncludeContentType(boolean include)
public boolean getIncludeContentType()
public void setPublicId(java.lang.String id)
public Path getPath()
public void setLineMap(java.lang.String filename)
public LineMap getLineMap()
public void addCdataElement(java.lang.String elt)
public void print(org.w3c.dom.Node node) throws java.io.IOException
java.io.IOException
public void printNode(org.w3c.dom.Node node) throws java.io.IOException
java.io.IOException
public void startDocument(org.w3c.dom.Document document) throws java.io.IOException
java.io.IOException
public void startDocument() throws java.io.IOException
startDocument
in interface XMLWriter
java.io.IOException
public void endDocument() throws java.io.IOException
endDocument
in interface XMLWriter
java.io.IOException
public void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator
in interface XMLWriter
public void setLocation(java.lang.String filename, int line, int column)
filename
- the source filenameline
- the source linecolumn
- the source columnpublic void startElement(java.lang.String url, java.lang.String localName, java.lang.String qName) throws java.io.IOException
startElement
in interface XMLWriter
url
- the namespace urllocalName
- the local nameqName
- the qualified namejava.io.IOException
public void printHeader(java.lang.String top) throws java.io.IOException
top
- name of the top elementjava.io.IOException
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws java.io.IOException
startPrefixMapping
in interface XMLWriter
java.io.IOException
public void endPrefixMapping(java.lang.String prefix) throws java.io.IOException
endPrefixMapping
in interface XMLWriter
java.io.IOException
public void attribute(java.lang.String uri, java.lang.String localName, java.lang.String qName, java.lang.String value) throws java.io.IOException
public boolean finishAttributes() throws java.io.IOException
java.io.IOException
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws java.io.IOException
endElement
in interface XMLWriter
uri
- the namespace uri of the elementlocalName
- the localname of the element tagqName
- qualified name of the elementjava.io.IOException
public void processingInstruction(java.lang.String name, java.lang.String data) throws java.io.IOException
processingInstruction
in interface XMLWriter
name
- the name of the processing instructiondata
- the processing instruction datajava.io.IOException
public void comment(java.lang.String data) throws java.io.IOException
public boolean getEscapeText()
getEscapeText
in interface XMLWriter
public void setEscapeText(boolean isEscaped)
setEscapeText
in interface XMLWriter
public void text(java.lang.String text) throws java.io.IOException
public void text(char[] buffer, int offset, int length) throws java.io.IOException
public void cdata(java.lang.String text) throws java.io.IOException