public class XmlSequWriter
extends java.lang.Object
#testWritetree2(File, StringBuilder)
etc with following template:
open(file, "US-ASCII", out); writeElement("root"); writeText("contentRoot", true); writeElement("child1"); writeAttribute("attr", "value"); writeText("contentChild <???> special chars", false); writeElementEnd(); writeElement("child2"); writeAttribute("attr2", "text ? special chars"); close();The output for that is:
<?xml version="1.0" encoding="US-ASCII"?> <root> contentRoot <child1 attr="value">contentChild <ÄÜÖ> special chars</child1> <child2 attr2="text € special chars"/> </root>Note: The source contains the transcription for Javadoc. See the original. Javadoc presents correctly.
CodeCharset
Modifier and Type | Class and Description |
---|---|
private class |
XmlSequWriter.ElementInfo |
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
bElementStart |
(package private) boolean |
bFullEncoding
true then no reason to output transcription characters.
|
boolean |
bTreeComment |
(package private) XmlSequWriter.ElementInfo |
elementCurr
Info of the current element.
|
(package private) java.util.Stack<XmlSequWriter.ElementInfo> |
elementsParent
Store all parent elements, necessary for close etc.
|
(package private) java.nio.charset.Charset |
encoding |
(package private) CodeCharset |
encodingCode
It is null for UTF encoding
|
private java.io.OutputStream |
fwr |
(package private) int |
indent |
(package private) int |
nColumn |
(package private) int |
nColumnMax |
private byte[] |
outBuffer |
private java.lang.String |
replaceBasics |
(package private) java.lang.String |
sEncoding |
private static java.lang.String |
sIndent |
private static java.lang.String[] |
stdReplacement |
private java.lang.Appendable |
twr |
static java.lang.String |
version
Version, License and History:
2020-10-05 check encoding stuff, some better documented and changed.
|
private java.io.Writer |
wr |
Constructor and Description |
---|
XmlSequWriter() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Writes closing elementsParent if necessary, then close the files.
|
void |
fileclose() |
void |
flush() |
java.lang.String |
open(java.io.File file,
java.lang.String encoding,
java.lang.Appendable buffer)
Opens for writing in a file, closes an opened file if any is open.
|
void |
replaceNewline(boolean bReplace)
Switch the mode for replacing a \n in texts or attribute values.
|
void |
setDebugTextOut(java.lang.Appendable out)
Sets an output for text output of the created XML.
|
void |
setEncoding(java.lang.String sEncoding) |
void |
writeAttribute(java.lang.String name,
java.lang.String value) |
void |
writeComment() |
void |
writeElement(java.lang.String sTag)
Writes a new Element with its tag, without closing the element.
|
void |
writeElementEnd()
Writes a simple end "" or "/>" depending on invocation of
#writeElementHeadEnd() before |
void |
writeElementHeadEnd(boolean bNewline)
Writes a simple end ">" because child nodes may be added to the element.
|
private void |
writeHead() |
void |
writeText(java.lang.CharSequence txt,
boolean bNewline) |
private void |
wrNewline(int add) |
private void |
wrTxt(java.lang.CharSequence txt)
Writes text with all replacements.
|
private void |
wrTxtAscii(java.lang.String txt)
Write as given, only ASCII (7 bit) especially for XML head.
|
private void |
wrTxtEncoded(java.lang.CharSequence txt)
Write a text, using
#encoding2 to check write character immediately
or as ģ for non encode able character. |
public static final java.lang.String version
private java.io.Writer wr
private java.io.OutputStream fwr
private java.lang.Appendable twr
private byte[] outBuffer
java.lang.String sEncoding
java.nio.charset.Charset encoding
CodeCharset encodingCode
boolean bFullEncoding
boolean bElementStart
int nColumn
int nColumnMax
XmlSequWriter.ElementInfo elementCurr
java.util.Stack<XmlSequWriter.ElementInfo> elementsParent
int indent
private java.lang.String replaceBasics
public boolean bTreeComment
private static java.lang.String sIndent
private static java.lang.String[] stdReplacement
public void setEncoding(java.lang.String sEncoding) throws java.nio.charset.IllegalCharsetNameException
java.nio.charset.IllegalCharsetNameException
public java.lang.String open(java.io.File file, java.lang.String encoding, java.lang.Appendable buffer) throws java.io.IOException
file
- can be null, then only the buffer is written.encoding
- can be null, then the last used or given setEncoding(String)
is valid.
Default is "UTF-8". If given the setEncoding(String)
is called here.
buffer
- can be null, if given, the output is written there, the same as in setDebugTextOut(Appendable)
The buffer is written with replaced characters by 샞 as in file.java.io.IOException
- only on closing an opened file. Not expected.public void close() throws java.io.IOException
java.io.IOException
public void flush() throws java.io.IOException
java.io.IOException
public void fileclose()
public void setDebugTextOut(java.lang.Appendable out)
#open(File, String)
is not used respectively close()
is called before,
the XML output is written only to this Appendable.
If #open(File, String)
is used too, the XML output is written twice, to this Appendable too.
The Appendable instance can used outside of this XML write operations in any kind, it can be delete etc.
Hence it may be used as debug check.out
- if null then this output is disabled.public void replaceNewline(boolean bReplace)
bReplace
- true, then do not output a \n (line break), instead output
false then break the line with \n if it occurs in texts and attribute values.private void writeHead() throws java.io.IOException
java.io.IOException
public void writeComment()
public void writeElement(java.lang.String sTag) throws java.io.IOException
writeElement(String)
before.
After this call firstly writeAttribute(String, String)
can be written,
then writeElement(String)
for child nodes or #writeText()
sTag
- java.io.IOException
private void wrNewline(int add) throws java.io.IOException
java.io.IOException
public void writeElementHeadEnd(boolean bNewline) throws java.io.IOException
java.io.IOException
public void writeElementEnd() throws java.io.IOException
#writeElementHeadEnd()
beforejava.io.IOException
public void writeAttribute(java.lang.String name, java.lang.String value) throws java.io.IOException
java.io.IOException
public void writeText(java.lang.CharSequence txt, boolean bNewline) throws java.io.IOException
java.io.IOException
private void wrTxt(java.lang.CharSequence txt) throws java.io.IOException
txt
- java.io.IOException
private void wrTxtEncoded(java.lang.CharSequence txt) throws java.io.IOException
#encoding2
to check write character immediately
or as ģ for non encode able character.
All character which are defined in thetxt
- java.io.IOException
private void wrTxtAscii(java.lang.String txt) throws java.io.IOException
txt
- java.io.IOException