Package org.apache.cxf.helpers
Class DOMUtils
java.lang.Object
org.apache.cxf.helpers.DOMUtils
Few simple utils to read DOM. This is originally from the Jakarta Commons Modeler.
- 
Nested Class SummaryNested Classes
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidaddNamespacePrefix(Element element, String namespaceUri, String prefix) Add a namespace prefix definition to an element.convertStringsToQNames(List<String> expandedQNames) static QNameconvertStringToQName(String expandedQName) static QNameconvertStringToQName(String expandedQName, String prefix) static Documentstatic StringcreateNamespace(Element el, String ns) static QNamecreateQName(String qualifiedName, Node node) Creates a QName object based on the qualified name and using the Node as a base to lookup the namespace for the prefixfindAllElementsByTagName(Element elem, String tagName) findAllElementsByTagNameNS(Element elem, String nameSpaceURI, String localName) static ElementfindChildWithAtt(Node parent, String elemName, String attName, String attVal) Find the first direct child with a given attribute.static StringGet the text content of a node and all it's children or null if there is no textstatic StringgetAttribute(Element element, QName attName) static StringgetAttribute(Node element, String attName) static StringgetAttributeValueEmptyNull(Element e, String attributeName) This function is much like getAttribute, but returns null, not "", for a nonexistent attribute.static NodeGet the first child of the specified type.static NodeGet the first element child.static StringgetChildContent(Node parent, String name) Get the first child's content ( ie it's included TEXT node ).getChildrenWithName(Element parent, String ns, String localName) Return child elements with specified name.getChildrenWithNamespace(Element parent, String ns) Returns all child elements with specified namespace.static StringgetContent(Node n) Get the trimmed text content of a node or null if there is no textstatic DocumentFragmentgetDomDocumentFragment(DocumentFragment fragment) Try to get the DOM DocumentFragment from the SAAJ DocumentFragment with JAVA9 afterwardsstatic NodegetDomElement(Node node) Try to get the DOM Node from the SAAJ Node with JAVA9 afterwardsstatic QNamestatic DocumentReturns a static Document that should always be "empty".static ElementgetFirstChildWithName(Element parent, String ns, String lp) Return the first element child with the specified qualified name.static ElementgetFirstChildWithName(Element parent, QName q) Return the first element child with the specified qualified name.static ElementgetFirstElement(Node parent) Get the first direct child with a given typestatic StringgetNamespace(Node node, String searchPrefix) Starting from a node, find the namespace declaration for a prefix. for a matching namespace declaration.static NodeGet the next sibling with the same name and typestatic NodeReturn the next sibling with a given name and typestatic Elementstatic Stringstatic voidgetPrefixes(Element element, String namespaceUri, List<String> prefixes) Get all prefixes defined on this element for the specified namespace.static voidgetPrefixesRecursive(Element element, String namespaceUri, List<String> prefixes) Get all prefixes defined, up to the root, for a namespace URI.static StringgetPrefixRecursive(Element el, String ns) static StringGet the raw text content of a node or null if there is no textstatic booleanhasAttribute(Element element, String value) static booleanhasElementInNS(Element el, String namespace) static booleanhasElementWithName(Element el, String nameSpaceURI, String localName) static booleanstatic DocumentCreates a new Document objectstatic voidremoveAttribute(Node node, String attName) static voidsetAttribute(Node node, String attName, String val) static StringsetNamespace(Element element, String namespace, String prefix) Set a namespace/prefix on an element if it is not set already.static voidSet or replace the text value
- 
Method Details- 
newDocumentCreates a new Document object- Throws:
- ParserConfigurationException
 
- 
createDocument
- 
getEmptyDocumentReturns a static Document that should always be "empty". It's useful as a factory for for creating Elements and other nodes that will be traversed later and don't need to be attached into a document- Returns:
- an empty document
 
- 
getAttributeValueEmptyNullThis function is much like getAttribute, but returns null, not "", for a nonexistent attribute.- Parameters:
- e-
- attributeName-
 
- 
getAllContentGet the text content of a node and all it's children or null if there is no text
- 
getContentGet the trimmed text content of a node or null if there is no text
- 
getRawContentGet the raw text content of a node or null if there is no text
- 
getChildGet the first element child.- Parameters:
- parent- lookup direct childs
- name- name of the element. If null return the first element.
 
- 
hasAttribute
- 
getAttribute
- 
getAttribute
- 
setAttribute
- 
removeAttribute
- 
setTextSet or replace the text value
- 
findChildWithAttFind 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
 
- 
getChildContentGet the first child's content ( ie it's included TEXT node ).
- 
getElementQName
- 
createQNameCreates a QName object based on the qualified name and using the Node as a base to lookup the namespace for the prefix- Parameters:
- qualifiedName-
- node-
 
- 
convertStringToQName
- 
convertStringToQName
- 
convertStringsToQNames
- 
getFirstElementGet the first direct child with a given type
- 
getNextElement
- 
getFirstChildWithNameReturn the first element child with the specified qualified name.- Parameters:
- parent-
- q-
 
- 
getFirstChildWithNameReturn the first element child with the specified qualified name.- Parameters:
- parent-
- ns-
- lp-
 
- 
getChildrenWithNameReturn child elements with specified name.- Parameters:
- parent-
- ns-
- localName-
 
- 
getChildrenWithNamespaceReturns all child elements with specified namespace.- Parameters:
- parent- the element to search under
- ns- the namespace to find elements in
- Returns:
- all child elements with specified namespace
 
- 
getChildGet the first child of the specified type.- Parameters:
- parent-
- type-
 
- 
getNextGet the next sibling with the same name and type
- 
getNextReturn the next sibling with a given name and type
- 
getPrefixRecursive
- 
getPrefix
- 
getPrefixesRecursivepublic static void getPrefixesRecursive(Element element, String namespaceUri, List<String> prefixes) Get all prefixes defined, up to the root, for a namespace URI.- Parameters:
- element-
- namespaceUri-
- prefixes-
 
- 
getPrefixesGet all prefixes defined on this element for the specified namespace.- Parameters:
- element-
- namespaceUri-
- prefixes-
 
- 
createNamespace
- 
getNamespaceStarting from a node, find the namespace declaration for a prefix. for a matching namespace declaration.- Parameters:
- node- search up from here to search for namespace definitions
- searchPrefix- the prefix we are searching for
- Returns:
- the namespace if found.
 
- 
findAllElementsByTagNameNS
- 
getDomElementTry to get the DOM Node from the SAAJ Node with JAVA9 afterwards- Parameters:
- node- The original node we need check
- Returns:
- The DOM node
 
- 
getDomDocumentFragmentTry to get the DOM DocumentFragment from the SAAJ DocumentFragment with JAVA9 afterwards- Parameters:
- fragment- The original documentFragment we need to check
- Returns:
- The DOM DocumentFragment
 
- 
findAllElementsByTagName
- 
hasElementWithName
- 
hasElementInNS
- 
setNamespaceSet a namespace/prefix on an element if it is not set already. First off, it searches for the element for the prefix associated with the specified namespace. If the prefix isn't null, then this is returned. Otherwise, it creates a new attribute using the namespace/prefix passed as parameters.- Parameters:
- element-
- namespace-
- prefix-
- Returns:
- the prefix associated with the set namespace
 
- 
addNamespacePrefixAdd a namespace prefix definition to an element.- Parameters:
- element-
- namespaceUri-
- prefix-
 
- 
isJava9SAAJpublic static boolean isJava9SAAJ()
 
-