public class XMLWrite extends Object
By default, we assume that the XML stuff is written to a StringBuffer, and indentation is used to beautify the output. After a call to 'open()', an additional indent is added after each line-separator, this shifting the text to the right. The text is left-shifted by the 'close()' method.
To add more complete XML stuff, use 'add'. This is an example of who we can add the settings <position x="0.0" y="1.0"/> to the writer:
XMLWriter xw = new XMLWriter();
xw.add("x","0.0");
xw.add("y","1.0");
xw.set("position");
To open a new field and add elements, use 'open()', e.g.:
xw.open("context");
xw.addSetting("Just this, folks");
xw.close();
creates something like
Just this, folks
</context>
The string buffer can be reset to 0 at any time. If not reset, the settings are continuously added.
XMLRead| Constructor and Description |
|---|
XMLWrite()
Builds the XML writer class with default settings.
|
XMLWrite(String indent)
Builds the XML writer.
|
XMLWrite(String indent,
String ls)
Builds the XML writer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(String attr,
String val)
Set an attribute of a setting.
|
void |
addData(String data)
Adds data to the buffer.
|
void |
addSettings(String s)
Add a value (or eventually a sub-set of valid XML stuff) to the current
buffer.
|
void |
clear()
Resets the string buffer to zero.
|
void |
close()
Adds a simple setting to a string(buffer), notifying a closing tag: the
tag is preceded by a / (e.g.
|
String |
getSettings()
Returns the settings currently added to the buffer in a string
|
void |
open()
Shifts the text an indent to the right (open a new field).
|
void |
open(String key)
Adds an opening tag to a string(buffer).
|
void |
set(String key)
Adds a key to a string(buffer).
|
void |
set(String key,
BasicStroke f)
Adds a font setting to a string(buffer).
|
void |
set(String key,
Color c)
Adds a color setting to a string(buffer).
|
void |
set(String key,
Font f)
Adds a font setting to a string(buffer).
|
void |
setData(String key,
double double_data)
Adds data between within the scope of a tag.
|
void |
setData(String key,
int integer_data)
Adds data between within the scope of a tag.
|
void |
setData(String key,
String data)
Adds data between within the scope of a tag.
|
void |
setIndent(String indent)
Sets the indentation, a number of spaces.
|
void |
setSeparator(String s)
This method resets the separator between settings to a specific string.
|
void |
setShift(String ii)
Sets the initial indentation level, a number of spaces.
|
public XMLWrite()
public XMLWrite(String indent)
indent - indentation (right-shift)public XMLWrite(String indent, String ls)
indent - indentation (right-shift)ls - new line separatorpublic void set(String key)
key - key or name of the XML itempublic void open(String key)
key - key or name of the XML itempublic void close()
public void set(String key, Color c)
key - key or name of the XML itemc - a color instancepublic void set(String key, Font f)
key - key or name of the XML itemf - a font instancepublic void set(String key, BasicStroke f)
key - key or name of the XML itemf - a stroke instancepublic String getSettings()
public void setSeparator(String s)
s - new line separatorpublic void setShift(String ii)
ii - initial indentationpublic void setIndent(String indent)
indent - indentationpublic void open()
public void clear()
public void addSettings(String s)
s - string with settings.public void add(String attr, String val)
attr - name of the attributeval - value of the attributepublic void addData(String data)
data - data or valuesopen(String),
close(),
setData(String,String)public void setData(String key, String data)
key - key or name of the XML itemopen(String),
addData(String),
close()public void setData(String key, double double_data)
key - key or name of the XML itemopen(String),
addData(String),
close()public void setData(String key, int integer_data)
key - key or name of the XML itemopen(String),
addData(String),
close()Jas4pp 1.5 © Java Analysis Studio for Particle Physics