org.codehaus.xfire.util
Class DOMUtils

java.lang.Object
  extended by org.codehaus.xfire.util.DOMUtils

public class DOMUtils
extends Object

Few simple utils to read DOM. This is originally from the Jakarta Commons Modeler.

Author:
Costin Manolache

Nested Class Summary
static class DOMUtils.NullResolver
           
 
Constructor Summary
DOMUtils()
           
 
Method Summary
static Document createDocument()
           
static Node findChildWithAtt(Node parent, String elemName, String attName, String attVal)
          Find the first direct child with a given attribute.
static String getAttribute(Node element, String attName)
           
static Node getChild(Node parent, int type)
          Get the first direct child with a given type
static Node getChild(Node parent, String name)
          Get the first element child.
static String getChildContent(Node parent, String name)
          Get the first child's content ( ie it's included TEXT node ).
static String getContent(Node n)
          Get the trimed text content of a node or null if there is no text
static Node getNext(Node current)
          Get the next sibling with the same name and type
static Node getNext(Node current, String name, int type)
          Return the next sibling with a given name and type
static String getRawContent(Node n)
          Get the raw text content of a node or null if there is no text
static Document readXml(InputStream is)
          Read XML as DOM.
static void removeAttribute(Node node, String attName)
           
static void setAttribute(Node node, String attName, String val)
           
static void setText(Node node, String val)
          Set or replace the text value
static void writeXml(Node n, OutputStream os)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMUtils

public DOMUtils()
Method Detail

getRawContent

public static String getRawContent(Node n)
Get the raw text content of a node or null if there is no text


getContent

public static String getContent(Node n)
Get the trimed text content of a node or null if there is no text


getChild

public static Node getChild(Node parent,
                            String name)
Get the first element child.

Parameters:
parent - lookup direct childs
name - name of the element. If null return the first element.

getAttribute

public static String getAttribute(Node element,
                                  String attName)

setAttribute

public static void setAttribute(Node node,
                                String attName,
                                String val)

removeAttribute

public static void removeAttribute(Node node,
                                   String attName)

setText

public static void setText(Node node,
                           String val)
Set or replace the text value


findChildWithAtt

public static Node findChildWithAtt(Node parent,
                                    String elemName,
                                    String attName,
                                    String attVal)
Find the first direct child with a given attribute.

Parameters:
parent -
elemName - name of the element, or null for any
attName - attribute we're looking for
attVal - attribute value or null if we just want any

getChildContent

public static String getChildContent(Node parent,
                                     String name)
Get the first child's content ( ie it's included TEXT node ).


getChild

public static Node getChild(Node parent,
                            int type)
Get the first direct child with a given type


getNext

public static Node getNext(Node current)
Get the next sibling with the same name and type


getNext

public static Node getNext(Node current,
                           String name,
                           int type)
Return the next sibling with a given name and type


readXml

public static Document readXml(InputStream is)
                        throws SAXException,
                               IOException,
                               ParserConfigurationException
Read XML as DOM.

Throws:
SAXException
IOException
ParserConfigurationException

writeXml

public static void writeXml(Node n,
                            OutputStream os)
                     throws TransformerException
Throws:
TransformerException

createDocument

public static Document createDocument()


Copyright © 2004-2013. All Rights Reserved.