com.threed.jpct.util
Class XMLFactory

java.lang.Object
  extended bycom.threed.jpct.util.XMLFactory

public final class XMLFactory
extends java.lang.Object

XMLFactory is a small factory to parse XML-files. XMLFactory and XMLNode provide a simple and fast possibility to parse XML-files without the overhead of other, much bigger XML-libraries. The possibilities of this approach may be limited but at least it's fast, small and easy to use.
The XML won't be validated against its DTD or schema.


Method Summary
 void filter(XMLNode xmlRoot, XMLNode xmlFilter)
          Removes nodes from the tree whose path don't match the filter-node's path.
static XMLFactory getInstance()
          Returns the instance of the XMLFactory.
 java.util.Vector getMatchingNodes(java.lang.String pattern, XMLNode node)
          Gets the nodes that match the pattern in "mynode/mynode2/mynode3"-form starting from the given node.
 XMLNode parseXML(java.lang.String xml)
          Parses the xml.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static XMLFactory getInstance()
Returns the instance of the XMLFactory. The XMLFactory is a singleton.

Returns:
the instance of the factory

parseXML

public XMLNode parseXML(java.lang.String xml)
Parses the xml. As mentioned, the whole parser is a small and quite simple implementation. While it should be able to parse wellformed xml files without problems, it may choke on unvalid ones. It could be a good idea to place this call into a try-catch-block...
After parsing, the XML will be stored in a tree-structure where the tags are the nodes.

Parameters:
xml - the xml to parse
Returns:
the root-node of the XML-tree. May be null in case of parsing problems.

filter

public void filter(XMLNode xmlRoot,
                   XMLNode xmlFilter)
Removes nodes from the tree whose path don't match the filter-node's path. (The "path" is the concatenation of the nodes' names, for example "/root/node1/node2/node3/").

Parameters:
xmlRoot - the root of the XML-tree
xmlFilter - the filter to apply

getMatchingNodes

public java.util.Vector getMatchingNodes(java.lang.String pattern,
                                         XMLNode node)
Gets the nodes that match the pattern in "mynode/mynode2/mynode3"-form starting from the given node. To get the matching nodes in the example above, "node" needs to be the XML-node of "mynode" or in other words: The first node in the pattern has to be the name of the starting node.

Parameters:
pattern - the pattern
node - the starting node
Returns:
A Vector of the nodes that match the criteria