Java XML Element Get getElementsWithName(Document doc, String name)

Here you can find the source of getElementsWithName(Document doc, String name)

Description

Write all links if it has a CatalogID and recurse to contained ids

License

Apache License

Declaration

public static Element[] getElementsWithName(Document doc, String name) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.*;

import java.util.*;

public class Main {
    /**//from w w  w  . ja  v a  2s .  c o  m
    Write all links if it has a CatalogID and recurse to contained ids
     */
    public static Element[] getElementsWithName(Document doc, String name) {
        NodeList nodes = doc.getElementsByTagName(name);
        int n = nodes.getLength();
        List holder = new ArrayList(n);
        for (int i = 0; i < n; i++) {
            Node item = nodes.item(i);
            if (item.getNodeType() == Node.ELEMENT_NODE)
                holder.add(item);
        }
        Element[] ret = new Element[holder.size()];
        holder.toArray(ret);
        return (ret);
    }

    /**
    Write all links if it has a CatalogID and recurse to contained ids
     */
    public static Element[] getElementsWithName(Element doc, String name) {
        NodeList nodes = doc.getElementsByTagName(name);
        int n = nodes.getLength();
        List holder = new ArrayList(n);
        for (int i = 0; i < n; i++) {
            Node item = nodes.item(i);
            if (item.getNodeType() == Node.ELEMENT_NODE)
                holder.add(item);
        }
        Element[] ret = new Element[holder.size()];
        holder.toArray(ret);
        return (ret);
    }
}

Related

  1. getElementsByTagName(Element node, String tagName)
  2. getElementsByTagName(Element node, String xmlns, String nodeName)
  3. getElementsByTagNameNS1(Element element, String nsName, String tagName)
  4. getElementsByTagNameNS1(Element element, String nsName, String tagName)
  5. getElementsByXpath(Document docInput, String xPath)
  6. getElementText(Document owner, String elementName, String nsURI)
  7. getElementWithKeyFromDocument(final Document document, final String key)