|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectCommon.myXML
public class myXML
Title: XML parser/generator
Description: WEB applet for X10 Linux Universal Device Drivers
Copyright: Copyright (c) 2003
License: GPL
Summary:This is a poor man's version of a DOM like XML reader/writer written specifically so that it is
very small and ideal for an applet.
The format supported is as followed:
<?xml version="1.0" standalone="yes"?>
<!-- Comment -->
<rootname>
<tag>
<tag attribute1="value" attribute2="value">elementvalue</tag>
</tag>
</rootname>
The following are not supported:
How to create XML tree in memory to write to disk:
Example:
Results in the following:
<?xml version="1.0" standalone="yes"?>
<root>
<element1 attribute1="att1" attribute2="att2">value1</element1>
<element2 attribute20="att20">
<element21 attribute21="att21">value21</element21>
</element2>
</root>
Values for Elements and Attributes can be any type of object but will be converted to String by calling toString() before storing the value.
How to load XML tree from disk:
How to walk through the XML tree:
Nested Class Summary | |
---|---|
class |
myXML.Attribute
Attributes associated with element tags. |
static class |
myXML.myXMLEncodingException
Signals that the XML being parsed has an error in the encoding. |
static class |
myXML.myXMLException
Signals that a general exception has occurred. |
static class |
myXML.myXMLIOException
Signals that an I/O excetion has occurred. |
Field Summary | |
---|---|
myXML.Attribute |
Attribute
|
Constructor Summary | |
---|---|
myXML()
|
|
myXML(java.io.BufferedReader in)
Read the XML tree in from the specified stream. |
|
myXML(java.lang.String tag)
Create new myXML object with no subelements, no attributes, and no value |
Method Summary | |
---|---|
myXML |
addElement(java.lang.String tag)
Add a subelement which will be used as a branch in the XML tree to the this element of the form: <tag attr1="attr1value attr2="attr2value" ... |
myXML |
addElement(java.lang.String tag,
java.lang.Object value)
Add a leaf element to the XML tree of the form: <tag attr1="attr1value attr2="attr2value" ... |
boolean |
contains(myXML element)
Tests if the specified element is a subelement of this element |
myXML |
findattribute(java.lang.String name)
Find and retrieve the first element that has the specified attribute name. |
myXML |
findElement(java.lang.String tag)
Find and retrieve the first element that has the specified tag name The search starts with this object and follows all branch and leaf nodes in the XML tree. |
myXML |
findElement(java.lang.String tag,
java.lang.String attname)
Find and retrieve the first element that has the specified tag name and the specified attribute name. |
myXML |
getElement(int index)
Retrieve the element object at the specified index. |
java.lang.String |
getTag()
Retrieve the name/tag |
java.lang.String |
getValue()
Retrieve the data value for this element in String form |
boolean |
isEmpty()
Tests if this parent has no subelements |
boolean |
removeAllElements()
Removes all subelements from the specified parent |
boolean |
removeElement(myXML element)
Remove subelement (element) from list of objects for a parent element |
void |
serialize(java.io.PrintWriter out)
Write the XML tree to an output stream in text form. |
int |
size()
Retrieve the number of elements attached to this element |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public myXML.Attribute Attribute
Constructor Detail |
---|
public myXML(java.lang.String tag)
tag
- initial name for the XML element or null for empty elementpublic myXML()
public myXML(java.io.BufferedReader in) throws myXML.myXMLException, myXML.myXMLEncodingException, java.io.IOException
in
- BufferedReader input stream
myXML.myXMLException
myXML.myXMLEncodingException
java.io.IOException
Method Detail |
---|
public java.lang.String getTag()
public java.lang.String getValue()
public int size()
public myXML findElement(java.lang.String tag)
public boolean removeElement(myXML element) throws myXML.myXMLException
element
- element to be removed from object list of parent
myXML.myXMLException
public boolean contains(myXML element) throws myXML.myXMLException
element
- element to test
myXML.myXMLException
public boolean removeAllElements()
public boolean isEmpty()
public myXML findattribute(java.lang.String name)
public myXML findElement(java.lang.String tag, java.lang.String attname)
public myXML getElement(int index)
index
- integer indicating the branch or leaf of the this XML object
public myXML addElement(java.lang.String tag) throws myXML.myXMLException
tag
- String used to identify the element
myXML.myXMLException
public myXML addElement(java.lang.String tag, java.lang.Object value) throws myXML.myXMLException
tag
- String used to identify the elementvalue
- Object to use for the element value (Note that the object will
be converted to a String before storing in the XML tree.
myXML.myXMLException
public void serialize(java.io.PrintWriter out) throws java.io.IOException
out
- A PrintWriter object to be used as the output stream for the XML tree.
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |