Package org.apache.commons.modeler.util
Class DomUtil
- java.lang.Object
-
- org.apache.commons.modeler.util.DomUtil
-
public class DomUtil extends Object
Few simple utils to read DOM- Author:
- Costin Manolache
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DomUtil.NullResolver
-
Constructor Summary
Constructors Constructor Description DomUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 typestatic 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 textstatic Node
getNext(Node current)
Get the next sibling with the same name and typestatic Node
getNext(Node current, String name, int type)
Return the next sibling with a given name and typestatic 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
setAttributes(Object o, Node parent)
static void
setText(Node node, String val)
Set or replace the text valuestatic void
writeXml(Node n, OutputStream os)
-
-
-
Method Detail
-
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 childsname
- name of the element. If null return the first element.
-
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 anyattName
- attribute we're looking forattVal
- 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, 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.
-
writeXml
public static void writeXml(Node n, OutputStream os) throws TransformerException
- Throws:
TransformerException
-
-