@NotThreadSafe public class XMLEmitter extends Object implements AutoCloseable, Flushable
| Modifier and Type | Field and Description |
|---|---|
static String |
CDATA_END |
static String |
CDATA_START |
static String |
COMMENT_END |
static String |
COMMENT_START |
static boolean |
DEFAULT_THROW_EXCEPTION_ON_NESTED_COMMENTS
By default an exception is thrown for nested comments
|
static char |
ER_END |
static char |
ER_START |
static String |
PI_END |
static String |
PI_START |
| Constructor and Description |
|---|
XMLEmitter(Writer aWriter,
IXMLWriterSettings aSettings) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
elementAttr(String sAttrNamespacePrefix,
String sAttrName,
String sAttrValue) |
void |
elementStartClose(EXMLSerializeBracketMode eBracketMode) |
void |
elementStartOpen(String sNamespacePrefix,
String sTagName) |
void |
flush() |
static String |
getDocTypeHTMLRepresentation(EXMLSerializeVersion eXMLVersion,
EXMLIncorrectCharacterHandling eIncorrectCharHandling,
IMicroDocumentType aDocType)
Get the XML representation of a document type.
|
static String |
getDocTypeXMLRepresentation(EXMLSerializeVersion eXMLVersion,
EXMLIncorrectCharacterHandling eIncorrectCharHandling,
String sQualifiedName,
String sPublicID,
String sSystemID)
Get the XML representation of a document type.
|
IXMLWriterSettings |
getXMLWriterSettings() |
static boolean |
isThrowExceptionOnNestedComments() |
XMLEmitter |
newLine() |
void |
onCDATA(String sText)
CDATA node.
|
void |
onComment(String sComment)
Comment node.
|
void |
onContentElementWhitespace(CharSequence aWhitespaces)
Ignorable whitespace characters.
|
void |
onDocumentType(String sQualifiedElementName,
String sPublicID,
String sSystemID)
On XML document type.
|
void |
onDTD(String sDTD)
Write a DTD section.
|
void |
onElementEnd(String sNamespacePrefix,
String sTagName,
EXMLSerializeBracketMode eBracketMode)
End of an element.
|
void |
onElementStart(String sNamespacePrefix,
String sTagName,
Map<QName,String> aAttrs,
EXMLSerializeBracketMode eBracketMode)
Start of an element.
|
void |
onEntityReference(String sEntityRef)
On entity reference.
|
void |
onProcessingInstruction(String sTarget,
String sData)
On processing instruction
|
void |
onText(char[] aText,
int nOfs,
int nLen)
XML text node.
|
void |
onText(char[] aText,
int nOfs,
int nLen,
boolean bEscape)
Text node.
|
void |
onText(String sText)
XML text node.
|
void |
onText(String sText,
boolean bEscape)
Text node.
|
void |
onXMLDeclaration(EXMLVersion eXMLVersion,
String sEncoding,
com.helger.commons.state.ETriState eStandalone)
Deprecated.
|
void |
onXMLDeclaration(EXMLVersion eXMLVersion,
String sEncoding,
com.helger.commons.state.ETriState eStandalone,
boolean bWithNewLine)
At the very beginning of the document (XML declaration).
|
static void |
setThrowExceptionOnNestedComments(boolean bThrowExceptionOnNestedComments)
Define whether nested XML comments throw an exception or not.
|
String |
toString() |
public static final boolean DEFAULT_THROW_EXCEPTION_ON_NESTED_COMMENTS
public static final String CDATA_START
public static final String CDATA_END
public static final String COMMENT_START
public static final String COMMENT_END
public static final char ER_START
public static final char ER_END
public static final String PI_START
public static final String PI_END
public XMLEmitter(@Nonnull @WillNotClose Writer aWriter, @Nonnull IXMLWriterSettings aSettings)
public static void setThrowExceptionOnNestedComments(boolean bThrowExceptionOnNestedComments)
bThrowExceptionOnNestedComments - true to throw an exception, false to
ignore nested comments.public static boolean isThrowExceptionOnNestedComments()
true if nested XML comments will throw an error.
Default is true.@Nonnull public IXMLWriterSettings getXMLWriterSettings()
null.@Nonnull public XMLEmitter newLine()
@Deprecated public void onXMLDeclaration(@Nullable EXMLVersion eXMLVersion, @Nullable String sEncoding, @Nonnull com.helger.commons.state.ETriState eStandalone)
eXMLVersion - The XML version to use. If null is passed,
EXMLVersion.XML_10 will be used.sEncoding - The encoding to be used for this document. It may be
null but it is strongly recommended to write a correct
charset.eStandalone - if true this is a standalone XML document without a
connection to an existing DTD or XML schemapublic void onXMLDeclaration(@Nullable EXMLVersion eXMLVersion, @Nullable String sEncoding, @Nonnull com.helger.commons.state.ETriState eStandalone, boolean bWithNewLine)
eXMLVersion - The XML version to use. If null is passed,
EXMLVersion.XML_10 will be used.sEncoding - The encoding to be used for this document. It may be
null but it is strongly recommended to write a correct
charset.eStandalone - if true this is a standalone XML document without a
connection to an existing DTD or XML schemabWithNewLine - true to add a newline, false if notpublic void onDTD(@Nonnull String sDTD)
sDTD - the DTD to be written. May not be null.@Nonnull public static String getDocTypeHTMLRepresentation(@Nonnull EXMLSerializeVersion eXMLVersion, @Nonnull EXMLIncorrectCharacterHandling eIncorrectCharHandling, @Nonnull IMicroDocumentType aDocType)
eXMLVersion - The XML version to use. May not be null.eIncorrectCharHandling - The incorrect character handling. May not be null.aDocType - The structure document type. May not be null.@Nonnull public static String getDocTypeXMLRepresentation(@Nonnull EXMLSerializeVersion eXMLVersion, @Nonnull EXMLIncorrectCharacterHandling eIncorrectCharHandling, @Nonnull String sQualifiedName, @Nullable String sPublicID, @Nullable String sSystemID)
eXMLVersion - The XML version to use. May not be null.eIncorrectCharHandling - The incorrect character handling. May not be null.sQualifiedName - The qualified element name. May not be null.sPublicID - The optional public ID. May be null. If the public ID
is not null the system ID must also be set!sSystemID - The optional system ID. May be null.public void onDocumentType(@Nonnull String sQualifiedElementName, @Nullable String sPublicID, @Nullable String sSystemID)
sQualifiedElementName - Qualified name of the root element.sPublicID - Document type public IDsSystemID - Document type system IDpublic void onProcessingInstruction(@Nonnull String sTarget, @Nullable String sData)
sTarget - The targetsData - The data (attributes as a string)public void onEntityReference(@Nonnull String sEntityRef)
sEntityRef - The reference (without '&' and ';' !!)public void onContentElementWhitespace(@Nullable CharSequence aWhitespaces)
aWhitespaces - The whitespace character sequencepublic void onComment(@Nullable String sComment)
sComment - The comment textpublic void onText(@Nullable String sText)
sText - The contained textpublic void onText(@Nonnull char[] aText, @Nonnegative int nOfs, @Nonnegative int nLen)
aText - The contained text arraynOfs - Offset into the array where to startnLen - Number of chars to use, starting from the provided offset.public void onText(@Nullable String sText, boolean bEscape)
sText - The contained textbEscape - If true the text should be XML masked (the default),
false if not. The false case is especially
interesting for HTML inline JS and CSS code.public void onText(@Nonnull char[] aText, @Nonnegative int nOfs, @Nonnegative int nLen, boolean bEscape)
aText - The contained text arraynOfs - Offset into the array where to startnLen - Number of chars to use, starting from the provided offset.bEscape - If true the text should be XML masked (the default),
false if not. The false case is especially
interesting for HTML inline JS and CSS code.public void onCDATA(@Nullable String sText)
sText - The contained textpublic void elementStartOpen(@Nullable String sNamespacePrefix, @Nonnull String sTagName)
public void elementAttr(@Nullable String sAttrNamespacePrefix, @Nonnull String sAttrName, @Nonnull String sAttrValue)
public void elementStartClose(@Nonnull EXMLSerializeBracketMode eBracketMode)
public void onElementStart(@Nullable String sNamespacePrefix, @Nonnull String sTagName, @Nullable Map<QName,String> aAttrs, @Nonnull EXMLSerializeBracketMode eBracketMode)
sNamespacePrefix - Optional namespace prefix. May be null.sTagName - Tag nameaAttrs - Optional set of attributes.eBracketMode - Bracket mode to use. Never null.public void onElementEnd(@Nullable String sNamespacePrefix, @Nonnull String sTagName, @Nonnull EXMLSerializeBracketMode eBracketMode)
sNamespacePrefix - Optional namespace prefix. May be null.sTagName - Tag nameeBracketMode - Bracket mode to use. Never null.public void flush()
throws IOException
flush in interface FlushableIOExceptionpublic void close()
throws IOException
close in interface AutoCloseableIOExceptionCopyright © 2014–2019 Philip Helger. All rights reserved.