public class XMLWrite
extends java.lang.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(java.lang.String indent)
Builds the XML writer.
|
XMLWrite(java.lang.String indent,
java.lang.String ls)
Builds the XML writer.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String attr,
java.lang.String val)
Set an attribute of a setting.
|
void |
addData(java.lang.String data)
Adds data to the buffer.
|
void |
addSettings(java.lang.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.
|
java.lang.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(java.lang.String key)
Adds an opening tag to a string(buffer).
|
void |
set(java.lang.String key)
Adds a key to a string(buffer).
|
void |
set(java.lang.String key,
java.awt.BasicStroke f)
Adds a font setting to a string(buffer).
|
void |
set(java.lang.String key,
java.awt.Color c)
Adds a color setting to a string(buffer).
|
void |
set(java.lang.String key,
java.awt.Font f)
Adds a font setting to a string(buffer).
|
void |
setData(java.lang.String key,
double double_data)
Adds data between within the scope of a tag.
|
void |
setData(java.lang.String key,
int integer_data)
Adds data between within the scope of a tag.
|
void |
setData(java.lang.String key,
java.lang.String data)
Adds data between within the scope of a tag.
|
void |
setIndent(java.lang.String indent)
Sets the indentation, a number of spaces.
|
void |
setSeparator(java.lang.String s)
This method resets the separator between settings to a specific string.
|
void |
setShift(java.lang.String ii)
Sets the initial indentation level, a number of spaces.
|
public XMLWrite()
public XMLWrite(java.lang.String indent)
indent
- indentation (right-shift)public XMLWrite(java.lang.String indent, java.lang.String ls)
indent
- indentation (right-shift)ls
- new line separatorpublic void set(java.lang.String key)
key
- key or name of the XML itempublic void open(java.lang.String key)
key
- key or name of the XML itempublic void close()
public void set(java.lang.String key, java.awt.Color c)
key
- key or name of the XML itemc
- a color instancepublic void set(java.lang.String key, java.awt.Font f)
key
- key or name of the XML itemf
- a font instancepublic void set(java.lang.String key, java.awt.BasicStroke f)
key
- key or name of the XML itemf
- a stroke instancepublic java.lang.String getSettings()
public void setSeparator(java.lang.String s)
s
- new line separatorpublic void setShift(java.lang.String ii)
ii
- initial indentationpublic void setIndent(java.lang.String indent)
indent
- indentationpublic void open()
public void clear()
public void addSettings(java.lang.String s)
s
- string with settings.public void add(java.lang.String attr, java.lang.String val)
attr
- name of the attributeval
- value of the attributepublic void addData(java.lang.String data)
data
- data or valuesopen(String)
,
close()
,
setData(String,String)
public void setData(java.lang.String key, java.lang.String data)
key
- key or name of the XML itemopen(String)
,
addData(String)
,
close()
public void setData(java.lang.String key, double double_data)
key
- key or name of the XML itemopen(String)
,
addData(String)
,
close()
public void setData(java.lang.String key, int integer_data)
key
- key or name of the XML itemopen(String)
,
addData(String)
,
close()
JHepSim. A part of HSTOOLS. version-1.2