net.sf.zekr.engine.xml
Class XmlUtils

java.lang.Object
  extended by net.sf.zekr.engine.xml.XmlUtils

public class XmlUtils
extends java.lang.Object

Since:
Zekr 1.0
Version:
0.1
Author:
Mohsen Saboorian

Field Summary
static java.lang.String TEXT_NODE
           
 
Constructor Summary
XmlUtils()
           
 
Method Summary
static java.lang.String getAttr(org.w3c.dom.Node node, java.lang.String attr)
           
static org.w3c.dom.Element getElementByNamedAttr(org.w3c.dom.NodeList nodeList, java.lang.String tagName, java.lang.String attrName, java.lang.String attrValue)
          This methods looks into nodeList for any node matches <tagName> with an attribute attrNode.
static org.w3c.dom.Node getNode(org.w3c.dom.NodeList nodeList, java.lang.String tagName)
           
static NodeList getNodes(NodeList list, java.lang.String tagName)
           
static NodeList getNodes(org.w3c.dom.Node node, java.lang.String tagName)
           
static java.lang.String getParentAttr(org.w3c.dom.Node node, java.lang.String parentAttr)
           
static boolean isElement(org.w3c.dom.Node node, java.lang.String string)
           
static void setAttr(org.w3c.dom.Element element, java.lang.String attr, java.lang.String value)
           
static void writeXml(org.w3c.dom.Node node, java.io.File outputFile)
          Writes a org.w3c.Node object into an output file.
static void writeXml(org.w3c.dom.Node node, java.io.File outputFile, java.lang.String encoding)
          Writes a org.w3c.Node object into an output file, specifying output file encoding.
static void writeXml(org.w3c.dom.Node node, java.io.Writer outputWriter)
          Writes a org.w3c.Node object into an output Writer, omitting XML declaration.
static void writeXml(org.w3c.dom.Node node, java.io.Writer outputWriter, boolean omitXmlDecl)
          Writes a org.w3c.Node object into an output Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEXT_NODE

public static final java.lang.String TEXT_NODE
See Also:
Constant Field Values
Constructor Detail

XmlUtils

public XmlUtils()
Method Detail

getNode

public static org.w3c.dom.Node getNode(org.w3c.dom.NodeList nodeList,
                                       java.lang.String tagName)

getNodes

public static NodeList getNodes(org.w3c.dom.Node node,
                                java.lang.String tagName)
Parameters:
node - single Node.
tagName -
Returns:
all the nodes (tags) with the name of tagName which are present in node children (depth = 1).
Note that the return value is of type NodeList.

getNodes

public static NodeList getNodes(NodeList list,
                                java.lang.String tagName)
Parameters:
list -
tagName -
Returns:
all nodes in list with tag name equal to tagName

getElementByNamedAttr

public static org.w3c.dom.Element getElementByNamedAttr(org.w3c.dom.NodeList nodeList,
                                                        java.lang.String tagName,
                                                        java.lang.String attrName,
                                                        java.lang.String attrValue)
This methods looks into nodeList for any node matches <tagName> with an attribute attrNode.

Parameters:
nodeList - a list of Node s
tagName - tag name
attrName - tag attribute name
Returns:
the node with attrName equal to attrValue

getAttr

public static java.lang.String getAttr(org.w3c.dom.Node node,
                                       java.lang.String attr)
Parameters:
node -
attr -
Returns:
value of the named attribute or null if there is no such attribute

setAttr

public static void setAttr(org.w3c.dom.Element element,
                           java.lang.String attr,
                           java.lang.String value)
Parameters:
element -
attr -
value -

getParentAttr

public static java.lang.String getParentAttr(org.w3c.dom.Node node,
                                             java.lang.String parentAttr)
Parameters:
node -
parentAttr -
Returns:
value of the named attribute for parent node of node

isElement

public static boolean isElement(org.w3c.dom.Node node,
                                java.lang.String string)

writeXml

public static void writeXml(org.w3c.dom.Node node,
                            java.io.File outputFile)
                     throws javax.xml.transform.TransformerException
Writes a org.w3c.Node object into an output file.

Parameters:
node - a Node object to be written to file
outputFile - ouput file
Throws:
javax.xml.transform.TransformerException

writeXml

public static void writeXml(org.w3c.dom.Node node,
                            java.io.File outputFile,
                            java.lang.String encoding)
                     throws javax.xml.transform.TransformerException
Writes a org.w3c.Node object into an output file, specifying output file encoding.

Parameters:
node - a Node object to be written to file
outputFile - ouput file
encoding - encoding of the output file
Throws:
javax.xml.transform.TransformerException

writeXml

public static void writeXml(org.w3c.dom.Node node,
                            java.io.Writer outputWriter)
                     throws javax.xml.transform.TransformerException
Writes a org.w3c.Node object into an output Writer, omitting XML declaration.

Parameters:
node - node object to be written to file
outputWriter - ouput writer object
Throws:
javax.xml.transform.TransformerException

writeXml

public static void writeXml(org.w3c.dom.Node node,
                            java.io.Writer outputWriter,
                            boolean omitXmlDecl)
                     throws javax.xml.transform.TransformerException
Writes a org.w3c.Node object into an output Writer.

Parameters:
node - node object to be written to file
outputWriter - ouput writer object
omitXmlDecl - omits XML declaration if true
Throws:
javax.xml.transform.TransformerException