org.jboss.ws.api.util
Class DOMUtils
- java.lang.Object
- org.jboss.ws.api.util.DOMUtils
public abstract class DOMUtils extends Object
Basic DOM2 utilities- Author:
- Alessio Soldano, Thomas Diesler
Constructor Summary
Constructors Constructor and Description DOMUtils()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static void
copyAttributes(Element destElement, Element srcElement)
Copy attributes between elementsstatic Element
createElement(String localPart, String prefix, String uri, Document doc)
Create an Element for a given name, prefix and uristatic Map<QName,String>
getAttributes(Element el)
Get the attributes as Map<QName, String>static String
getAttributeValue(Element el, QName attrName)
Get the value from the given attributestatic String
getAttributeValue(Element el, String attrName)
Get the value from the given attributestatic boolean
getAttributeValueAsBoolean(Element el, QName attrName)
Get the boolean value from the given attributestatic boolean
getAttributeValueAsBoolean(Element el, String attrName)
Get the boolean value from the given attributestatic Integer
getAttributeValueAsInteger(Element el, QName attrName)
Get the integer value from the given attributestatic Integer
getAttributeValueAsInteger(Element el, String attrName)
Get the integer value from the given attributestatic QName
getAttributeValueAsQName(Element el, QName attrName)
Get the qname value from the given attributestatic QName
getAttributeValueAsQName(Element el, String attrName)
Get the qname value from the given attributestatic Iterator<Element>
getChildElements(Node node)
Gets child elementsstatic Iterator<Element>
getChildElements(Node node, QName nodeName)
Gets the child element for a given qnamestatic Iterator<Element>
getChildElements(Node node, QName nodeName, boolean recursive)
Gets the child element for a given qnamestatic Iterator<Element>
getChildElements(Node node, String nodeName)
Gets the child elements for a given local name without namespacestatic Iterator<Element>
getChildElements(Node node, String nodeName, boolean recursive)
Gets the child elements for a given local name without namespacestatic List<Element>
getChildElementsAsList(Node node, QName nodeName)
static List<Element>
getChildElementsAsList(Node node, QName nodeName, boolean recursive)
static List<Element>
getChildElementsAsList(Node node, String nodeName)
static List<Element>
getChildElementsAsList(Node node, String nodeName, boolean recursive)
static QName
getElementQName(Element el)
Get the qname of the given node.static Element
getFirstChildElement(Node node)
Gets the first child elementstatic Element
getFirstChildElement(Node node, boolean recursive)
Gets the first child elementstatic Element
getFirstChildElement(Node node, QName nodeName)
Gets the first child element for a given qnamestatic Element
getFirstChildElement(Node node, QName nodeName, boolean recursive)
Gets the first child element for a given qnamestatic Element
getFirstChildElement(Node node, String nodeName)
Gets the first child element for a given local name without namespacestatic Element
getFirstChildElement(Node node, String nodeName, boolean recursive)
Gets the first child element for a given local name without namespacestatic Element
getParentElement(Node node)
Gets parent element or null if there is nonestatic String
getTextContent(Node node)
Get the concatenated text content, or null.static boolean
hasChildElements(Node node)
True if the node has child elementsstatic boolean
hasTextChildNodesOnly(Node node)
True if the node has text child elements onlystatic Element
parse(InputSource source, DocumentBuilder builder)
Parse the given input source and return the root Elementstatic Element
parse(InputStream xmlStream, DocumentBuilder builder)
Parse the given XML stream and return the root Elementstatic Element
parse(String xmlString, DocumentBuilder builder)
Parse the given XML string and return the root Elementstatic QName
resolveQName(Element el, String qualifiedName)
Transform the given qualified name into a QNamestatic Element
sourceToElement(Source source, DocumentBuilder builder)
Method Detail
getElementQName
public static QName getElementQName(Element el)
Get the qname of the given node.- Parameters:
el
- node- Returns:
- Qname
resolveQName
public static QName resolveQName(Element el, String qualifiedName)
Transform the given qualified name into a QName- Parameters:
el
- nodequalifiedName
- qualified name- Returns:
- QName
getAttributeValue
public static String getAttributeValue(Element el, String attrName)
Get the value from the given attribute- Parameters:
el
- elementattrName
- attribute name- Returns:
- null if the attribute value is empty or the attribute is not present
getAttributeValue
public static String getAttributeValue(Element el, QName attrName)
Get the value from the given attribute- Parameters:
el
- elementattrName
- attribute name- Returns:
- null if the attribute value is empty or the attribute is not present
getAttributeValueAsQName
public static QName getAttributeValueAsQName(Element el, String attrName)
Get the qname value from the given attribute- Parameters:
el
- elementattrName
- attribute name- Returns:
- QName
getAttributeValueAsQName
public static QName getAttributeValueAsQName(Element el, QName attrName)
Get the qname value from the given attribute- Parameters:
el
- elementattrName
- attribute name- Returns:
- QName
getAttributeValueAsBoolean
public static boolean getAttributeValueAsBoolean(Element el, String attrName)
Get the boolean value from the given attribute- Parameters:
el
- elementattrName
- attribute name- Returns:
- boolean
getAttributeValueAsBoolean
public static boolean getAttributeValueAsBoolean(Element el, QName attrName)
Get the boolean value from the given attribute- Parameters:
el
- elementattrName
- attribute name- Returns:
- boolean
getAttributeValueAsInteger
public static Integer getAttributeValueAsInteger(Element el, String attrName)
Get the integer value from the given attribute- Parameters:
el
- elementattrName
- attribute name- Returns:
- Integer
getAttributeValueAsInteger
public static Integer getAttributeValueAsInteger(Element el, QName attrName)
Get the integer value from the given attribute- Parameters:
el
- elementattrName
- attribute name- Returns:
- Integer
getAttributes
public static Map<QName,String> getAttributes(Element el)
Get the attributes as Map<QName, String>- Parameters:
el
- element- Returns:
- Map
copyAttributes
public static void copyAttributes(Element destElement, Element srcElement)
Copy attributes between elements- Parameters:
destElement
- elementsrcElement
- element
hasTextChildNodesOnly
public static boolean hasTextChildNodesOnly(Node node)
True if the node has text child elements only- Parameters:
node
- start node- Returns:
- True if the node has text child
hasChildElements
public static boolean hasChildElements(Node node)
True if the node has child elements- Parameters:
node
- start node- Returns:
- true when child has elements
getChildElements
public static Iterator<Element> getChildElements(Node node)
Gets child elements- Parameters:
node
- start node- Returns:
- Iterator
getTextContent
public static String getTextContent(Node node)
Get the concatenated text content, or null.- Parameters:
node
- node- Returns:
- string
getFirstChildElement
public static Element getFirstChildElement(Node node)
Gets the first child element- Parameters:
node
- start node- Returns:
- element
getFirstChildElement
public static Element getFirstChildElement(Node node, boolean recursive)
Gets the first child element- Parameters:
node
- childrecursive
- recurse flag- Returns:
- element
getFirstChildElement
public static Element getFirstChildElement(Node node, String nodeName)
Gets the first child element for a given local name without namespace- Parameters:
node
- childnodeName
- name- Returns:
- element
getFirstChildElement
public static Element getFirstChildElement(Node node, String nodeName, boolean recursive)
Gets the first child element for a given local name without namespace- Parameters:
node
- childnodeName
- namerecursive
- recurse flag- Returns:
- element
getFirstChildElement
public static Element getFirstChildElement(Node node, QName nodeName)
Gets the first child element for a given qname- Parameters:
node
- childnodeName
- name- Returns:
- element
getFirstChildElement
public static Element getFirstChildElement(Node node, QName nodeName, boolean recursive)
Gets the first child element for a given qname- Parameters:
node
- childnodeName
- namerecursive
- recurse flag- Returns:
- element
getChildElements
public static Iterator<Element> getChildElements(Node node, String nodeName)
Gets the child elements for a given local name without namespace- Parameters:
node
- childnodeName
- name- Returns:
- Iterator
getChildElements
public static Iterator<Element> getChildElements(Node node, String nodeName, boolean recursive)
Gets the child elements for a given local name without namespace- Parameters:
node
- childnodeName
- namerecursive
- recurse flag- Returns:
- Iterator
getChildElements
public static Iterator<Element> getChildElements(Node node, QName nodeName)
Gets the child element for a given qname- Parameters:
node
- childnodeName
- name- Returns:
- Iterator
getChildElements
public static Iterator<Element> getChildElements(Node node, QName nodeName, boolean recursive)
Gets the child element for a given qname- Parameters:
node
- childnodeName
- namerecursive
- recurse flag- Returns:
- Iterator
getChildElementsAsList
public static List<Element> getChildElementsAsList(Node node, String nodeName)
getChildElementsAsList
public static List<Element> getChildElementsAsList(Node node, String nodeName, boolean recursive)
getChildElementsAsList
public static List<Element> getChildElementsAsList(Node node, QName nodeName, boolean recursive)
getParentElement
public static Element getParentElement(Node node)
Gets parent element or null if there is none- Parameters:
node
- child- Returns:
- element
sourceToElement
public static Element sourceToElement(Source source, DocumentBuilder builder) throws IOException
- Throws:
IOException
parse
public static Element parse(String xmlString, DocumentBuilder builder) throws IOException
Parse the given XML string and return the root Element- Parameters:
xmlString
- string to be parsedbuilder
- document builder- Returns:
- element
- Throws:
IOException
- exception
parse
public static Element parse(InputStream xmlStream, DocumentBuilder builder) throws IOException
Parse the given XML stream and return the root Element- Parameters:
xmlStream
- input streambuilder
- document builder- Returns:
- element
- Throws:
IOException
- exception
parse
public static Element parse(InputSource source, DocumentBuilder builder) throws IOException
Parse the given input source and return the root Element- Parameters:
source
- input sourcebuilder
- document builder- Returns:
- element
- Throws:
IOException
- exception
Copyright © 2018 JBoss, by Red Hat. All rights reserved.