org.apache.ws.commons.schema.utils
Class DOMUtil

java.lang.Object
  extended by org.apache.ws.commons.schema.utils.DOMUtil
Direct Known Subclasses:
XDOMUtil

public class DOMUtil
extends Object

Some useful utility methods. This class was modified in Xerces2 with a view to abstracting as much as possible away from the representation of the underlying parsed structure (i.e., the DOM). This was done so that, if Xerces ever adopts an in-memory representation more efficient than the DOM (such as a DTM), we should easily be able to convert our schema parsing to utilize it.

Version:
$ID DOMUtil

Constructor Summary
protected DOMUtil()
          This class cannot be instantiated.
 
Method Summary
static Attr getAttr(Element elem, String name)
           
static Attr getAttrNS(Element elem, String nsUri, String localName)
           
static Attr[] getAttrs(Element elem)
           
static String getAttrValue(Element elem, String name)
           
static String getAttrValueNS(Element elem, String nsUri, String localName)
           
static String getChildText(Node node)
          Returns the concatenated child text of the specified node.
static Document getDocument(Node node)
           
static Element getFirstChildElement(Node parent)
          Finds and returns the first child element node.
static Element getFirstChildElement(Node parent, String elemName)
          Finds and returns the first child node with the given name.
static Element getFirstChildElement(Node parent, String[] elemNames)
          Finds and returns the first child node with the given name.
static Element getFirstChildElement(Node parent, String elemName, String attrName, String attrValue)
          Finds and returns the first child node with the given name and attribute name, value pair.
static Element getFirstChildElementNS(Node parent, String[][] elemNames)
          Finds and returns the first child node with the given qualified name.
static Element getFirstChildElementNS(Node parent, String uri, String localpart)
          Finds and returns the first child node with the given qualified name.
static String getInputEncoding(Document doc)
          Get the input encoding of the document.
static Element getLastChildElement(Node parent)
          Finds and returns the last child element node.
static Element getLastChildElement(Node parent, String elemName)
          Finds and returns the last child node with the given name.
static Element getLastChildElement(Node parent, String[] elemNames)
          Finds and returns the last child node with the given name.
static Element getLastChildElement(Node parent, String elemName, String attrName, String attrValue)
          Finds and returns the last child node with the given name and attribute name, value pair.
static Element getLastChildElementNS(Node parent, String[][] elemNames)
          Finds and returns the last child node with the given qualified name.
static Element getLastChildElementNS(Node parent, String uri, String localpart)
          Finds and returns the last child node with the given qualified name.
static String getLocalName(Node node)
          returns local name of this element if not null, otherwise returns the name of the node
static String getName(Node node)
           
static String getNamespaceURI(Node node)
           
static Element getNextSiblingElement(Node node)
          Finds and returns the next sibling element node.
static Element getNextSiblingElement(Node node, String elemName)
          Finds and returns the next sibling node with the given name.
static Element getNextSiblingElement(Node node, String[] elemNames)
          Finds and returns the next sibling node with the given name.
static Element getNextSiblingElement(Node node, String elemName, String attrName, String attrValue)
          Finds and returns the next sibling node with the given name and attribute name, value pair.
static Element getNextSiblingElementNS(Node node, String[][] elemNames)
          Finds and returns the next sibling node with the given qualified name.
static Element getNextSiblingElementNS(Node node, String uri, String localpart)
          Finds and returns the next sibling node with the given qualified name.
static Element getParent(Element elem)
           
static Element getRoot(Document doc)
           
static String getValue(Attr attribute)
           
static String getXmlEncoding(Document doc)
          Get the xml encoding of the document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMUtil

protected DOMUtil()
This class cannot be instantiated.

Method Detail

getFirstChildElement

public static Element getFirstChildElement(Node parent)
Finds and returns the first child element node.


getLastChildElement

public static Element getLastChildElement(Node parent)
Finds and returns the last child element node.


getNextSiblingElement

public static Element getNextSiblingElement(Node node)
Finds and returns the next sibling element node.


getFirstChildElement

public static Element getFirstChildElement(Node parent,
                                           String elemName)
Finds and returns the first child node with the given name.


getLastChildElement

public static Element getLastChildElement(Node parent,
                                          String elemName)
Finds and returns the last child node with the given name.


getNextSiblingElement

public static Element getNextSiblingElement(Node node,
                                            String elemName)
Finds and returns the next sibling node with the given name.


getFirstChildElementNS

public static Element getFirstChildElementNS(Node parent,
                                             String uri,
                                             String localpart)
Finds and returns the first child node with the given qualified name.


getLastChildElementNS

public static Element getLastChildElementNS(Node parent,
                                            String uri,
                                            String localpart)
Finds and returns the last child node with the given qualified name.


getNextSiblingElementNS

public static Element getNextSiblingElementNS(Node node,
                                              String uri,
                                              String localpart)
Finds and returns the next sibling node with the given qualified name.


getFirstChildElement

public static Element getFirstChildElement(Node parent,
                                           String[] elemNames)
Finds and returns the first child node with the given name.


getLastChildElement

public static Element getLastChildElement(Node parent,
                                          String[] elemNames)
Finds and returns the last child node with the given name.


getNextSiblingElement

public static Element getNextSiblingElement(Node node,
                                            String[] elemNames)
Finds and returns the next sibling node with the given name.


getFirstChildElementNS

public static Element getFirstChildElementNS(Node parent,
                                             String[][] elemNames)
Finds and returns the first child node with the given qualified name.


getLastChildElementNS

public static Element getLastChildElementNS(Node parent,
                                            String[][] elemNames)
Finds and returns the last child node with the given qualified name.


getNextSiblingElementNS

public static Element getNextSiblingElementNS(Node node,
                                              String[][] elemNames)
Finds and returns the next sibling node with the given qualified name.


getFirstChildElement

public static Element getFirstChildElement(Node parent,
                                           String elemName,
                                           String attrName,
                                           String attrValue)
Finds and returns the first child node with the given name and attribute name, value pair.


getLastChildElement

public static Element getLastChildElement(Node parent,
                                          String elemName,
                                          String attrName,
                                          String attrValue)
Finds and returns the last child node with the given name and attribute name, value pair.


getNextSiblingElement

public static Element getNextSiblingElement(Node node,
                                            String elemName,
                                            String attrName,
                                            String attrValue)
Finds and returns the next sibling node with the given name and attribute name, value pair. Since only elements have attributes, the node returned will be of type Node.ELEMENT_NODE.


getChildText

public static String getChildText(Node node)
Returns the concatenated child text of the specified node. This method only looks at the immediate children of type Node.TEXT_NODE or the children of any child node that is of type Node.CDATA_SECTION_NODE for the concatenation.

Parameters:
node - The node to look at.

getName

public static String getName(Node node)

getLocalName

public static String getLocalName(Node node)
returns local name of this element if not null, otherwise returns the name of the node


getParent

public static Element getParent(Element elem)

getDocument

public static Document getDocument(Node node)

getRoot

public static Element getRoot(Document doc)

getAttr

public static Attr getAttr(Element elem,
                           String name)

getAttrNS

public static Attr getAttrNS(Element elem,
                             String nsUri,
                             String localName)

getAttrs

public static Attr[] getAttrs(Element elem)

getValue

public static String getValue(Attr attribute)

getAttrValue

public static String getAttrValue(Element elem,
                                  String name)

getAttrValueNS

public static String getAttrValueNS(Element elem,
                                    String nsUri,
                                    String localName)

getNamespaceURI

public static String getNamespaceURI(Node node)

getInputEncoding

public static String getInputEncoding(Document doc)
Get the input encoding of the document. This uses a DOM 3 API call getInputEncoding hence it returns the correct value only if a DOM3 API is used. Otherwise it returns the default encoding

Parameters:
doc -
Returns:
the encoding (e.g. UTF-8)

getXmlEncoding

public static String getXmlEncoding(Document doc)
Get the xml encoding of the document. This uses a DOM 3 API call getXmlEncoding hence it returns the correct value only if a DOM3 API is used. Otherwise it returns the default encoding

Parameters:
doc -
Returns:
the encoding (e.g. utf-8).
See Also:
getInputEncoding(Document)


Copyright © 2004-2015 The Apache Software Foundation. All Rights Reserved.