Class XML
java.lang.Object
javaforce.XML
XML encapsules a complete XML file.
Each XML tag (element) is treated as a node in the tree. The read() functions include a callback interface so you can further tweak the layout of the XML tree.
Then you can write() it back to a file. Typical XML Tag:
<name [attributes...]> content | children </name>
Singleton XML Tag: (no children)
<name [attributes...] />
Caveats:
Only leaf nodes can contain actual data (content) (in other words @XmlMixed is not supported).
Mixed tags are read, but when written the content is lost.
There must be only one root tag.
Support for the standard XML header is provided (see header).
readClass() and writeClass() support : int, short, byte, float, double, boolean, String, and Custom Classes.
Arrays of any of these.
All classes and fields MUST be public. static and transient members are skipped. No special annotations are required.
Each XML tag (element) is treated as a node in the tree. The read() functions include a callback interface so you can further tweak the layout of the XML tree.
Then you can write() it back to a file. Typical XML Tag:
<name [attributes...]> content | children </name>
Singleton XML Tag: (no children)
<name [attributes...] />
Caveats:
Only leaf nodes can contain actual data (content) (in other words @XmlMixed is not supported).
Mixed tags are read, but when written the content is lost.
There must be only one root tag.
Support for the standard XML header is provided (see header).
readClass() and writeClass() support : int, short, byte, float, double, boolean, String, and Custom Classes.
Arrays of any of these.
All classes and fields MUST be public. static and transient members are skipped. No special annotations are required.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassXMLAttr is one attribute that is listed in each XML tag.class -
Field Summary
FieldsModifier and TypeFieldDescriptionThe XML header tag.The root tag. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSetTag(XML.XMLTag targetParent, String name, String attrs, String content) Adds (a non-existing) or sets (an existing) node with the name, attrs and content specified.addTag(XML.XMLTag targetParent, String name, String attrs, String content) Adds node with the name, attrs and content specified.addTag(XML.XMLTag parent, XML.XMLTag tag) Adds the node to the targetParent.Creates an empty node that can be inserted into the tree using addTag().voidDeletes the entire tree and resets the root and header tags.booleandeleteTag(XML.XMLTag tag) Deletes a node from the parent.getName(XML.XMLTag tag) Returns the unique name of a node.Returns a node based on the objs[] path.booleanread(InputStream is) Reads the entire tree from a XML file from the InputStream.booleanReads the entire tree from a XML file from filename.voidReads entire XML tree from object (deletes entire tree first).voidreadClass(XML.XMLTag tag, Object obj) Reads all fields from an object and places into tag.voidsetName(XML.XMLTag tag, String newName) Sets the name of a node.voidSets the name, attrs and contents of the true root node.voidsetTag(XML.XMLTag tag, String name, String attrs, String content) Sets the name, attrs and content for an existing node.booleanwrite(OutputStream os) Writes the entire tree as a XML file to the OutputStream.booleanWrites the entire tree as a XML file to the filename.voidwriteClass(Object obj) Writes entire XML tree to object.voidwriteClass(XML.XMLTag tag, Object obj) Writes all children of tag to object.
-
Field Details
-
header
The XML header tag. -
root
The root tag.
-
-
Constructor Details
-
XML
public XML()Constructs a new XML object.
-
-
Method Details
-
read
Reads the entire tree from a XML file from filename.- Parameters:
filename- name of file to load XML data from
-
read
Reads the entire tree from a XML file from the InputStream.- Parameters:
is- InputStream to load XML data from
-
write
Writes the entire tree as a XML file to the filename. -
write
Writes the entire tree as a XML file to the OutputStream. -
deleteAll
public void deleteAll()Deletes the entire tree and resets the root and header tags. -
deleteTag
Deletes a node from the parent. Also deletes all it's children. -
createTag
Creates an empty node that can be inserted into the tree using addTag(). -
addTag
Adds the node to the targetParent. -
addTag
Adds node with the name, attrs and content specified. If another node already exists with the same name the new node's unique name will differ. -
addSetTag
Adds (a non-existing) or sets (an existing) node with the name, attrs and content specified. -
setRoot
-
getName
Returns the unique name of a node. -
setName
Sets the name of a node. It's unique name may differ when shown in a tree. -
getTag
Returns a node based on the objs[] path. -
setTag
Sets the name, attrs and content for an existing node. -
writeClass
Writes all children of tag to object. -
writeClass
Writes entire XML tree to object. -
readClass
Reads all fields from an object and places into tag. -
readClass
-