|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecteu.beesoft.gaia.util.XmlWriter
public class XmlWriter
This class is designed to write XML files. The reserved XML characters are replaced by standard entities. Class supports the automatic elements nesting.
Usage:
PrintWriter pw = ...
XmlWriter writer = new XmlWriter (pw);
writer.addElement ("first");
writer.addAttribute ("value", 50);
writer.addElement ("second");
writer.addAttribute ("next", "www");
writer.closeElement ("second");
writer.closeElement ("first");
writer.close ();
The code above builds this XML:
<?xml version="1.0" encoding="UTF-8" ?>
<first value="50">
<second next="www" />
</first>
| Constructor Summary | |
|---|---|
XmlWriter(java.io.PrintWriter output)
Creates a new XML writer with one-tab indentation and UTF-8 encoding. |
|
XmlWriter(java.io.PrintWriter output,
java.lang.String encoding)
Creates a new XML writer with one-tab indentation. |
|
XmlWriter(java.io.PrintWriter output,
java.lang.String encoding,
java.lang.String indentation)
Creates a new XML writer. |
|
| Method Summary | |
|---|---|
void |
addAttribute(java.lang.String name,
boolean value)
Adds an attribute to the current element. |
void |
addAttribute(java.lang.String name,
double value)
Adds an attribute to the current element. |
void |
addAttribute(java.lang.String name,
float value)
Adds an attribute to the current element. |
void |
addAttribute(java.lang.String name,
int value)
Adds an attribute to the current element. |
void |
addAttribute(java.lang.String name,
long value)
Adds an attribute to the current element. |
void |
addAttribute(java.lang.String name,
java.lang.Object value)
Adds an attribute to the current element. |
void |
addElement(java.lang.String tag)
Opens a new element in XML output. |
void |
close()
Flushes this XML writer and closes the underlaying PrintWriter. |
void |
closeElement(java.lang.String tag)
Closes current element in XML output. |
void |
flush()
Flushes this XML writer and underlaying PrintWriter. |
java.lang.String |
getIndentation()
Returns indentation string. |
void |
setIndentation(java.lang.String indentation)
Sets the indentation string. |
void |
setText(java.lang.String text)
Sets text to the current element. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XmlWriter(java.io.PrintWriter output)
output - - writer to which this instance should write
public XmlWriter(java.io.PrintWriter output,
java.lang.String encoding)
output - - writer to which this instance should writeencoding - - encoding string to write to XML header
public XmlWriter(java.io.PrintWriter output,
java.lang.String encoding,
java.lang.String indentation)
output - - writer to which this instance should writeencoding - - encoding string to write to XML headerindentation - - string used to indentation of the elements| Method Detail |
|---|
public void flush()
public void close()
public void setIndentation(java.lang.String indentation)
indentation - - the indentation string to setpublic java.lang.String getIndentation()
public void addElement(java.lang.String tag)
tag - - element name (tag)public void closeElement(java.lang.String tag)
tag must be the
same as was used in addElement(String) when opening this
element.
tag - - element name (tag)
public void addAttribute(java.lang.String name,
boolean value)
name - - attribute namevalue - - attribute value
public void addAttribute(java.lang.String name,
int value)
name - - attribute namevalue - - attribute value
public void addAttribute(java.lang.String name,
long value)
name - - attribute namevalue - - attribute value
public void addAttribute(java.lang.String name,
float value)
name - - attribute namevalue - - attribute value
public void addAttribute(java.lang.String name,
double value)
name - - attribute namevalue - - attribute value
public void addAttribute(java.lang.String name,
java.lang.Object value)
value is
null, it writes to XML as attribute value string "
<null>".
name - - attribute namevalue - - attribute valuepublic void setText(java.lang.String text)
text - - text to set to the current element
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||