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 classDomUtil.NullResolver
-
Constructor Summary
Constructors Constructor Description DomUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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, int type)Get the first direct child with a given typestatic NodegetChild(Node parent, String name)Get the first element child.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 textstatic NodegetNext(Node current)Get the next sibling with the same name and typestatic NodegetNext(Node current, String name, int type)Return the next sibling with a given name and typestatic 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 valuestatic voidwriteXml(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
-
-