org.bibalex.daf.handlers.xmlhandler
Class XmlHandler

java.lang.Object
  extended by org.bibalex.daf.handlers.xmlhandler.XmlHandler

public class XmlHandler
extends java.lang.Object

This class performs XML related tasks, such as:
Getting a specific node using XPath.
Converting a Node into a String.

Author:
Shehab.Kamal

Field Summary
private  javax.xml.xpath.XPath xpath
          Holds the XPath used to execute queries.
 
Constructor Summary
XmlHandler()
          Initilaizes a new insatcne of XmlHandler.
 
Method Summary
static java.lang.String convertNode(org.w3c.dom.Node node)
          Converts the given xml node into a String.
static java.lang.String encode(java.lang.String xml)
          Encodes the given String to be in a valid XML format.
This method replaces the follwoing characters:
Char Replacement
& &
< &lt;
> &gt;
' &apos;
" &quot;
 org.w3c.dom.Node getNode(org.w3c.dom.Node node, java.lang.String query)
          Gets the node specified by the given query.
 org.w3c.dom.NodeList getNodes(org.w3c.dom.Node node, java.lang.String query)
          Gets the nodes specified by the given query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xpath

private javax.xml.xpath.XPath xpath
Holds the XPath used to execute queries.

Constructor Detail

XmlHandler

public XmlHandler()
Initilaizes a new insatcne of XmlHandler.

Method Detail

getNode

public org.w3c.dom.Node getNode(org.w3c.dom.Node node,
                                java.lang.String query)
Gets the node specified by the given query.

Parameters:
node - The Node on whose the XPath will be executed.
query - The XPath query to execute.
Returns:
An XmlNode that mathces the given XPath or null if no such node exists.

getNodes

public org.w3c.dom.NodeList getNodes(org.w3c.dom.Node node,
                                     java.lang.String query)
Gets the nodes specified by the given query.

Parameters:
node - The Node on whose the XPath will be executed.
query - The XPath query to execute.
Returns:
XmlNodes that mathces the given XPath or null if no such node exists.

convertNode

public static java.lang.String convertNode(org.w3c.dom.Node node)
Converts the given xml node into a String.

Parameters:
node - The node to convert into string.
Returns:
A String repesentation of the node or empty String if an excpetion occurs.

encode

public static java.lang.String encode(java.lang.String xml)
Encodes the given String to be in a valid XML format.
This method replaces the follwoing characters:
Char Replacement
& &amp;
< &lt;
> &gt;
' &apos;
" &quot;

Parameters:
xml - The String to encode.
Returns:
The encoded xml string.