createEmptyTag
public static final String createEmptyTag(String tagName)
Convenience method for creating an empty tag
having no attributes. E.g. <tagName/>
.
tagName
- name of the tag
createEmptyTag
public static final String createEmptyTag(String tagName,
Attributes attributes)
Convenience method for creating an empty tag.
tagName
- name of the tag
createEmptyTag
public static final String createEmptyTag(String tagName,
String attrName,
String attrValue)
Convenience method for creating an empty tag.
tagName
- name of the tagattrName
- name of attribute to be included into tagattrValue
- value of attribute to be included into tag,
if attrValue is null
attribute will not be included
createEmptyTag
public static final String createEmptyTag(String tagName,
String[] attrNames,
String[] attrValues)
Convenience method for creating an empty tag.
tagName
- name of the tagattrNames
- names of attributes to be included into tagattrValues
- values of attributes to be included into tag -
there should be just as many entries as in attrNames
,
if a value is null
corresponding attribute will not be included
createEmptyTag
public static final String createEmptyTag(String tagName,
String[][] attrPairs)
Convenience method for creating an empty tag.
tagName
- name of the tagattrPairs
- name/value pairs of attributes to be included into tag -
if a value is null
corresponding attribute will not be included
createEndTag
public static final String createEndTag(String tagName)
Convenience method for creating an end tag.
tagName
- name of the end tag
createStartTag
public static final String createStartTag(String tagName)
Convenience method for creating a start tag having no attributes.
tagName
- name of the start tag
createStartTag
public static final String createStartTag(String tagName,
Attributes attributes)
Convenience method for creating a start tag.
tagName
- name of the start tag
createStartTag
public static final String createStartTag(String tagName,
Attributes attributes,
boolean isEmpty)
Convenience method for creating a start tag.
tagName
- name of the start tagisEmpty
- decides wheter this is start tag is for an empty element
createStartTag
public static final String createStartTag(String tagName,
Attributes attributes,
boolean isEmpty,
boolean encodeAttrs,
char quoteChar)
Convenience method for creating a start tag.
tagName
- name of the start tagisEmpty
- decides wheter this is start tag is for an empty elementencodeAttrs
- set this to have your attribute values encoded for XMLquoteChar
- if you choose encoding this is the char that quotes
your attributes
createStartTag
public static final String createStartTag(String tagName,
String attrName,
String attrValue)
Convenience method for creating a non empty start tag.
tagName
- name of the start tagattrName
- name of attribute to be included into start tagattrValue
- value of attribute to be included into start tag,
if attrValue is null
attribute will not be included
createStartTag
public static final String createStartTag(String tagName,
String attrName,
String attrValue,
boolean isEmpty)
Convenience method for creating a start tag.
tagName
- name of the start tagattrName
- name of attribute to be included into start tagattrValue
- value of attribute to be included into start tag,
if attrValue is null
attribute will not be includedisEmpty
- decides wheter this is start tag is for an empty element
createStartTag
public static final String createStartTag(String tagName,
String[] attrNames,
String[] attrValues)
Convenience method for creating a non empty start tag.
tagName
- name of the start tagattrNames
- names of attributes to be included into start tagattrValues
- values of attributes to be included into start tag -
there should be just as many entries as in attrNames
,
if a value is null
corresponding attribute will not be included
createStartTag
public static final String createStartTag(String tagName,
String[] attrNames,
String[] attrValues,
boolean isEmpty)
Convenience method for creating a start tag.
tagName
- name of the start tagattrNames
- names of attributes to be included into start tagattrValues
- values of attributes to be included into start tag -
there should be just as many entries as in attrNames
,
if a value is null
corresponding attribute will not be includedisEmpty
- decides wheter this is start tag is for an empty element
createStartTag
public static final String createStartTag(String tagName,
String[] attrNames,
String[] attrValues,
boolean isEmpty,
boolean encodeAttrs,
char quoteChar)
Convenience method for creating a start tag.
tagName
- name of the start tagattrNames
- names of attributes to be included into start tagattrValues
- values of attributes to be included into start tag -
there should be just as many entries as in attrNames
,
if a value is null
corresponding attribute will not be includedisEmpty
- decides wheter this is start tag is for an empty elementencodeAttrs
- set this to have your attribute values encoded for XMLquoteChar
- if you choose encoding this is the char that quotes
your attributes
createStartTag
public static final String createStartTag(String tagName,
String[][] attrPairs)
Convenience method for creating a non empty start tag.
tagName
- name of the start tagattrPairs
- name/value pairs of attributes to be included into start tag -
if a value is null
corresponding attribute will not be included
createStartTag
public static final String createStartTag(String tagName,
String[][] attrPairs,
boolean isEmpty)
Convenience method for creating a start tag.
tagName
- name of the start tagattrPairs
- name/value pairs of attributes to be included into start tag -
if a value is null
corresponding attribute will not be includedisEmpty
- decides wheter this is start tag is for an empty element
createStartTag
public static final String createStartTag(String tagName,
String[][] attrPairs,
boolean isEmpty,
boolean encodeAttrs,
char quoteChar)
Convenience method for creating a start tag.
tagName
- name of the start tagattrPairs
- name/value pairs of attributes to be included into start tag -
if a value is null
corresponding attribute will not be includedisEmpty
- decides wheter this is start tag is for an empty elementencodeAttrs
- set this to have your attribute values encoded for XMLquoteChar
- if you choose encoding this is the char that quotes
your attributes
generateAndWriteElementWithCData
public static final void generateAndWriteElementWithCData(XMLWriter xmlWriter,
String tagName,
String[] attrNames,
String[] attrValues,
String cData)
throws IOException
Convenience method for creating and writing a whole element.
xmlWriter
- writer to write generated stuff totagName
- name of the elementattrNames
- names of attributes to be included into start tagattrValues
- values of attributes to be included into start tag -
there should be just as many entries as in attrNames
,
if a value is null
corresponding attribute will not be includedcData
- the character data of the element
generateAndWriteElementWithCData(XMLWriter,String,String[][],String)
, writeElementWithCData(String,String,String)
, createStartTag(String,String[],String[])
, createEndTag(String)
generateAndWriteElementWithCData
public static final void generateAndWriteElementWithCData(XMLWriter xmlWriter,
String tagName,
String[][] attrPairs,
String cData)
throws IOException
Convenience method for creating and writing a whole element.
Added to normal non-static write methods purely for my own laziness.
It is non-static as it differs from all other write methods as it
combines generating and writing. This is normally avoided to keep every
everything simple, clear and fast.
You can write
XMLOutputStreamWriter.generateAndWriteElementWithCData(writer, "tag", "cdata");
to generate
<tag>cdata</tag>
xmlWriter
- writer to write generated stuff totagName
- name of the elementattrPairs
- name/value pairs of attributes to be included into start tag -
if a value is null
corresponding attribute will not be includedcData
- the character data of the element
getNlAfterEmptyTag
public boolean getNlAfterEmptyTag()
getNlAfterEndTag
public boolean getNlAfterEndTag()
getNlAfterStartTag
public boolean getNlAfterStartTag()
getPrettyPrintMode
public boolean getPrettyPrintMode()
getTabWidth
public int getTabWidth()
isXMLDeclarationWritten
public boolean isXMLDeclarationWritten()
Indicates whether the XML declaration has been written, yet.
As it may only be written once, you can check this when writing
in different contexts to same writer.
setNlAfterEmptyTag
public void setNlAfterEmptyTag(boolean nlAfterEmptyTag)
Sets if a newline is inserted after an empty start element
by default.
setNlAfterEndTag
public void setNlAfterEndTag(boolean nlAfterEndTag)
Sets if a newline is inserted after an end tag
by default.
setNlAfterStartTag
public void setNlAfterStartTag(boolean nlAfterStartTag)
Sets if a newline is inserted after a non empty start tag
by default.
setPrettyPrintMode
public void setPrettyPrintMode(boolean prettyPrintMode)
Switches on/off pretty print mode.
Having it switched on (which is the default) makes output
pretty as newlines after tags and indentataion is done. Unfortunately,
if your application is sensible to whitespace in CDATA this might lead
to unwanted additional spaces and newlines.
If it is switched off the output is guaranteed to be correct, but looks
pretty funny. After before markup close (> or />) a newline is inserted
as otherwise you may get extremely long output lines.
setTabWidth
public void setTabWidth(int tabWidth)
Sets the amount of spaces to increase indentation with element level.
This only takes effect when
setPrettyPrintMode(boolean)
is set to true.
Caution: You should better avoid to change this property while
exporting as this may result in unexpected output.
setXMLDeclarationWritten
public void setXMLDeclarationWritten(boolean xmlDeclWritten)
writeCData
public void writeCData(String cData)
throws IOException
Writes character data with encoding.
cData
- the character data to write
writeComment
public void writeComment(String comment)
throws IOException
Writes comment
encoded as comment.
writeElementWithCData
public void writeElementWithCData(String startTag,
String cData,
String endTag)
throws IOException
Writes a full element consisting of a start tag, character data and
an end tag. There will be no newline after start tag, so character data
is literally preserved.
The character data will be encoded.
startTag
- the complete start tag, e.g. <element>
cData
- the character data to writeendTag
- the complete end tag, e.g. </element>
writeElementWithPCData
public void writeElementWithPCData(String startTag,
String pcData,
String endTag)
throws IOException
Writes a full element consisting of a start tag, character data and
an end tag. There will be no newline after start tag, so character data
is literally preserved.
The character data will not be encoded.
startTag
- the complete start tag, e.g. <element>
pcData
- the parseable character data to writeendTag
- the complete end tag, e.g. </element>
writeEmptyElement
public void writeEmptyElement(String emptyTag)
throws IOException
Writes an empty element.
emptyTag
- the complete tag for an empty element, e.g. <start/>
writeEmptyElement
public void writeEmptyElement(String emptyTag,
boolean nl)
throws IOException
Writes an empty element.
emptyTag
- the complete tag for an empty element, e.g. <empty/>
nl
- decides whether there should be a newline after the tag
writeEndTag
public void writeEndTag(String endTag)
throws IOException
Writes an end tag.
endTag
- the complete end tag, e.g. </end>
writeEndTag
public void writeEndTag(String endTag,
boolean nl)
throws IOException
Writes an end tag.
endTag
- the complete end tag, e.g. </end>
nl
- decides whether there should be a newline after the tag
writeNl
public void writeNl()
throws IOException
Writes a single newline.
writePCData
public void writePCData(String pcData)
throws IOException
Writes character data without encoding.
pcData
- the parseable character data to write
writePI
public void writePI(String target,
String data)
throws IOException
Writes a processing instruction.
writeProlog
public void writeProlog(String prolog)
throws IOException
Writes prolog data like doctype delcaration and
DTD parts followed by a newline.
Do not misuse this to write plain text, but rather - if you really
have to - use the standard XMLWriter
methods.
writeStartTag
public void writeStartTag(String startTag)
throws IOException
Writes a start tag.
startTag
- the complete start tag, e.g. <start>
writeStartTag
public void writeStartTag(String startTag,
boolean nl)
throws IOException
Writes a start tag.
startTag
- the complete start tag, e.g. <start>
nl
- decides whether there should be a newline after the tag
writeXMLDeclaration
public void writeXMLDeclaration()
throws IOException
Writes XML declaration.
XML declaration will be written
using version 1.0 and no encoding defaulting
to standard encoding (supports UTF-8 and UTF-16):
<?xml version="1.0"?>
If you want to have a different encoding or the standalone declaration
use
writeProlog(String)
.
This sets
xmlDeclWritten
to
true
.