|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.ChinaVO.FITSManager.XMLRWer
public class XMLRWer
This class is used for dealing the special xml format files:
<config>
<node1 name="">
<node2 name=""/>
</node1>
</config>
which node/element has only an attribute and the name of the attribute is
unique, such as "name","value"
You can read a node/element's attribute value, by get***value(path,
defaultValue),example:
getStringValue("config/node1", "");
The path = "config" + "/" + "node1".
Remark, after you new an object of this class, you should remember calling
the obj.loadXML() to start reading the xml file. Otherwise, you won't get
anything.
And before your application terminated, you should always remember calling
the obj.saveXML() to save back the information to your config.xml. If you
need not to save the new information, you can ignore this step.
example:
//"config" is the root node of the XML tree.
//"value" is the only attribute name for each node/element.
XMLRWer rw = new XMLRWer("value", "config");
rw.loadXML();//start reading the XML file.
rw.getBooleanValue("config/node1", true);//read some value
rw.setSetting("config/node3", "3");//change the node's value, if the node
does not exists, this operation will add a new node/element to the XML tree.
rw.saveXML();//save back the XML tree.
Constructor Summary | |
---|---|
XMLRWer(java.lang.String strValueAttrStr,
java.lang.String strRootName)
Construct a XMLRWer object. |
Method Summary | |
---|---|
boolean |
getBooleanValue(java.lang.String path,
boolean defaultValue)
get a Boolean value, if the path does not exists, return the defaultValue. |
double |
getDoubleValue(java.lang.String path,
double defaultValue)
get a Double value, if the path does not exists, return the defaultValue. |
int |
getIntValue(java.lang.String path,
int defaultValue)
get a Integer value, if the path does not exists, return the defaultValue. |
java.lang.String |
getRootName()
get the name of the XML file's root. |
java.lang.String |
getStringValue(java.lang.String path,
java.lang.String defaultValue)
get a String value, if the path does not exists, return the defaultValue. |
java.lang.String |
getValueAttrStr()
get the unique attribute's name |
java.lang.String |
getXMLPath()
get the XML file's path |
void |
loadXML()
Load the XML file. |
void |
saveXML()
Save back the xml tree to the xml file. |
void |
setSetting(java.lang.String path,
java.lang.String value)
change the attribute's value of a node/element which the path specify. |
void |
setXMLPath(java.lang.String strXMLPath)
Change the XML file's path. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLRWer(java.lang.String strValueAttrStr, java.lang.String strRootName)
strValueAttrStr
- name of the unique attribute.strRootName
- name of the XML tree's root.Method Detail |
---|
public void setXMLPath(java.lang.String strXMLPath)
strXMLPath
- new path of the XML file.public java.lang.String getXMLPath()
public java.lang.String getValueAttrStr()
public java.lang.String getRootName()
public int getIntValue(java.lang.String path, int defaultValue)
path
- like "config/system"defaultValue
- an Integer value, like 1,2,3¡¡
public boolean getBooleanValue(java.lang.String path, boolean defaultValue)
path
- like "config/system"defaultValue
- an Boolean value, like true,false
public double getDoubleValue(java.lang.String path, double defaultValue)
path
- like "config/system"defaultValue
- an Double value, like 1.0,2.2¡¡
public java.lang.String getStringValue(java.lang.String path, java.lang.String defaultValue)
path
- like "config/system"defaultValue
- an String value, like "","string"¡¡
public void setSetting(java.lang.String path, java.lang.String value)
path
- like "config/system"value
- new value, should be a Stringpublic void loadXML()
public void saveXML()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |