org.apache.tomcat.util

Class DomUtil

public class DomUtil extends Object

Few simple utils to read DOM

Author: Costin Manolache

Nested Class Summary
static classDomUtil.NullResolver
Method Summary
static NodefindChildWithAtt(Node parent, String elemName, String attName, String attVal)
Find the first direct child with a given attribute.
static StringgetAttribute(Node element, String attName)
static NodegetChild(Node parent, String name)
Get the first element child.
static NodegetChild(Node parent, int type)
Get the first direct child with a given type
static StringgetChildContent(Node parent, String name)
Get the first child's content ( ie it's included TEXT node ).
static StringgetContent(Node n)
Get the trimed text content of a node or null if there is no text
static NodegetNext(Node current)
Get the next sibling with the same name and type
static NodegetNext(Node current, String name, int type)
Return the next sibling with a given name and type
static DocumentreadXml(InputStream is)
Read XML as DOM.
static voidremoveAttribute(Node node, String attName)
static voidsetAttribute(Node node, String attName, String val)
static voidsetAttributes(Object o, Node parent)
static voidsetText(Node node, String val)
Set or replace the text value
static voidwriteXml(Node n, OutputStream os)

Method Detail

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

getAttribute

public static String getAttribute(Node element, String attName)

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.

getChild

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

getChildContent

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

getContent

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

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)
Read XML as DOM.

removeAttribute

public static void removeAttribute(Node node, String attName)

setAttribute

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

setAttributes

public static void setAttributes(Object o, Node parent)

setText

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

writeXml

public static void writeXml(Node n, OutputStream os)
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.