|
Apache CXF API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.cxf.helpers.DOMUtils
public final class DOMUtils
Few simple utils to read DOM. This is originally from the Jakarta Commons Modeler.
Nested Class Summary | |
---|---|
static class |
DOMUtils.NullResolver
|
Method Summary | |
---|---|
static void |
addNamespacePrefix(Element element,
String namespaceUri,
String prefix)
Add a namespace prefix definition to an element. |
static Document |
createDocument()
|
static DocumentBuilder |
createDocumentBuilder()
|
static String |
createNamespace(Element el,
String ns)
|
static List<Element> |
findAllElementsByTagName(Element elem,
String tagName)
|
static List<Element> |
findAllElementsByTagNameNS(Element elem,
String nameSpaceURI,
String localName)
|
static Node |
findChildWithAtt(Node parent,
String elemName,
String attName,
String attVal)
Find the first direct child with a given attribute. |
static String |
getAttribute(Element element,
QName attName)
|
static String |
getAttribute(Node element,
String attName)
|
static String |
getAttributeValueEmptyNull(Element e,
String attributeName)
This function is much like getAttribute, but returns null, not "", for a nonexistent attribute. |
static Node |
getChild(Node parent,
int type)
Get the first child of the specified 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 List<Element> |
getChildrenWithName(Element parent,
String ns,
String localName)
Return child elements with specified name. |
static List<Element> |
getChildrenWithNamespace(Element parent,
String ns)
Returns all child elements with specified namespace. |
static String |
getContent(Node n)
Get the trimmed text content of a node or null if there is no text |
static QName |
getElementQName(Element el)
|
static Element |
getFirstChildWithName(Element parent,
QName q)
Return the first element child with the specified qualified name. |
static Element |
getFirstChildWithName(Element parent,
String ns,
String lp)
Return the first element child with the specified qualified name. |
static Element |
getFirstElement(Node parent)
Get the first direct child with a given type |
static String |
getNamespace(Node node,
String searchPrefix)
Starting from a node, find the namespace declaration for a prefix. |
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 Element |
getNextElement(Element el)
|
static String |
getPrefix(Element el,
String ns)
|
static void |
getPrefixes(Element element,
String namespaceUri,
List<String> prefixes)
Get all prefixes defined on this element for the specified namespace. |
static void |
getPrefixesRecursive(Element element,
String namespaceUri,
List<String> prefixes)
Get all prefixes defined, up to the root, for a namespace URI. |
static String |
getPrefixRecursive(Element el,
String ns)
|
static String |
getRawContent(Node n)
Get the raw text content of a node or null if there is no text |
static boolean |
hasElementInNS(Element el,
String namespace)
|
static Document |
readXml(InputStream is)
Read XML as DOM. |
static Document |
readXml(Reader is)
|
static Document |
readXml(StreamSource is)
|
static void |
removeAttribute(Node node,
String attName)
|
static void |
setAttribute(Node node,
String attName,
String val)
|
static String |
setNamespace(Element element,
String namespace,
String prefix)
Set a namespace/prefix on an element if it is not set already. |
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 |
Method Detail |
---|
public static String getAttributeValueEmptyNull(Element e, String attributeName)
e
- attributeName
-
public static String getContent(Node n)
public static String getRawContent(Node n)
public static Node getChild(Node parent, String name)
parent
- lookup direct childsname
- name of the element. If null return the first element.public static String getAttribute(Node element, String attName)
public static String getAttribute(Element element, QName attName)
public static void setAttribute(Node node, String attName, String val)
public static void removeAttribute(Node node, String attName)
public static void setText(Node node, String val)
public static Node findChildWithAtt(Node parent, String elemName, String attName, String attVal)
parent
- elemName
- name of the element, or null for anyattName
- attribute we're looking forattVal
- attribute value or null if we just want anypublic static String getChildContent(Node parent, String name)
public static QName getElementQName(Element el)
public static Element getFirstElement(Node parent)
public static Element getNextElement(Element el)
public static Element getFirstChildWithName(Element parent, QName q)
parent
- q
-
public static Element getFirstChildWithName(Element parent, String ns, String lp)
parent
- ns
- lp
-
public static List<Element> getChildrenWithName(Element parent, String ns, String localName)
parent
- ns
- localName
-
public static List<Element> getChildrenWithNamespace(Element parent, String ns)
parent
- the element to search underns
- the namespace to find elements in
public static Node getChild(Node parent, int type)
parent
- type
-
public static Node getNext(Node current)
public static Node getNext(Node current, String name, int type)
public static Document readXml(InputStream is) throws SAXException, IOException, ParserConfigurationException
SAXException
IOException
ParserConfigurationException
public static Document readXml(Reader is) throws SAXException, IOException, ParserConfigurationException
SAXException
IOException
ParserConfigurationException
public static Document readXml(StreamSource is) throws SAXException, IOException, ParserConfigurationException
SAXException
IOException
ParserConfigurationException
public static void writeXml(Node n, OutputStream os) throws TransformerException
TransformerException
public static DocumentBuilder createDocumentBuilder()
public static Document createDocument()
public static String getPrefixRecursive(Element el, String ns)
public static String getPrefix(Element el, String ns)
public static void getPrefixesRecursive(Element element, String namespaceUri, List<String> prefixes)
element
- namespaceUri
- prefixes
- public static void getPrefixes(Element element, String namespaceUri, List<String> prefixes)
element
- namespaceUri
- prefixes
- public static String createNamespace(Element el, String ns)
public static String getNamespace(Node node, String searchPrefix)
node
- search up from here to search for namespace definitionssearchPrefix
- the prefix we are searching for
public static List<Element> findAllElementsByTagNameNS(Element elem, String nameSpaceURI, String localName)
public static List<Element> findAllElementsByTagName(Element elem, String tagName)
public static boolean hasElementInNS(Element el, String namespace)
public static String setNamespace(Element element, String namespace, String prefix)
element
- namespace
- prefix
-
public static void addNamespacePrefix(Element element, String namespaceUri, String prefix)
element
- namespaceUri
- prefix
-
|
Apache CXF API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |