Java Utililty Methods XML Node Select

List of utility methods to do XML Node Select

Description

The list of methods to do XML Node Select are organized into topic(s).

Method

ElementselectElement(Node node, String uri, String nodeName)
select Element
while (node != null) {
    if (nodeName.equals(node.getLocalName()) && uri.equals(node.getNamespaceURI()))
        return (Element) node;
    Element located = findElementinChilds(node, uri, nodeName);
    if (located != null) {
        return located;
return null;
NodeselectNode(Node node, String tag)
select Node
NodeList nodes = node.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
    Node n = nodes.item(i);
    if (n instanceof Element && ((Element) n).getTagName().equals(tag)) {
        return n;
return null;
...
ElementselectNode(Node sibling, String uri, String nodeName, int number)
select Node
while (sibling != null) {
    if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
            && sibling.getLocalName().equals(nodeName)) {
        if (number == 0) {
            return (Element) sibling;
        number--;
    sibling = sibling.getNextSibling();
return null;
ElementselectNode(Node sibling, String uri, String nodeName, int number)
select Node
while (sibling != null) {
    if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
            && sibling.getLocalName().equals(nodeName)) {
        if (number == 0) {
            return (Element) sibling;
        number--;
    sibling = sibling.getNextSibling();
return null;
ElementselectNode(Node sibling, String uri, String nodeName, int number)
select Node
while (sibling != null) {
    if (nodeName.equals(sibling.getLocalName()) && uri.equals(sibling.getNamespaceURI())) {
        if (number == 0) {
            return (Element) sibling;
        number--;
    sibling = sibling.getNextSibling();
...
NodeselectNodeByName(Node node, String nodeName)
Method selectNodeByName.
Node nodeToReturn = null;
int i = 0;
NodeList currNodes = node.getChildNodes();
int length = currNodes.getLength();
while ((i < length) && (nodeToReturn == null)) {
    Node thisNode = currNodes.item(i);
    if (thisNode.getNodeName().equals(nodeName)) {
        nodeToReturn = thisNode;
...
Element[]selectNodes(Node sibling, String uri, String nodeName)
select Nodes
List<Element> list = new ArrayList<Element>();
while (sibling != null) {
    if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
            && sibling.getLocalName().equals(nodeName)) {
        list.add((Element) sibling);
    sibling = sibling.getNextSibling();
return list.toArray(new Element[list.size()]);
Element[]selectNodes(Node sibling, String uri, String nodeName)
select Nodes
int size = 20;
Element[] a = new Element[size];
int curr = 0;
while (sibling != null) {
    if (nodeName.equals(sibling.getLocalName()) && uri.equals(sibling.getNamespaceURI())) {
        a[curr++] = (Element) sibling;
        if (size <= curr) {
            int cursize = size << 2;
...
TextselectNodeText(Node sibling, String uri, String nodeName, int number)
select Node Text
Node n = selectNode(sibling, uri, nodeName, number);
if (n == null) {
    return null;
n = n.getFirstChild();
while (n != null && n.getNodeType() != Node.TEXT_NODE) {
    n = n.getNextSibling();
return (Text) n;
TextselectNodeText(Node sibling, String uri, String nodeName, int number)
select Node Text
Node n = selectNode(sibling, uri, nodeName, number);
if (n == null) {
    return null;
n = n.getFirstChild();
while (n != null && n.getNodeType() != Node.TEXT_NODE) {
    n = n.getNextSibling();
return (Text) n;