Java XML Element Get getElementByFilter(Document doc, NodeFilter filter)

Here you can find the source of getElementByFilter(Document doc, NodeFilter filter)

Description

get Element By Filter

License

Open Source License

Declaration

public static List<Element> getElementByFilter(Document doc, NodeFilter filter) throws DOMException 

Method Source Code

//package com.java2s;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.DOMException;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Node;

import org.w3c.dom.traversal.DocumentTraversal;
import org.w3c.dom.traversal.NodeFilter;
import org.w3c.dom.traversal.NodeIterator;

public class Main {
    public static List<Element> getElementByFilter(Document doc, NodeFilter filter) throws DOMException {
        List<Element> result = new ArrayList<Element>();
        DocumentTraversal traversable = (DocumentTraversal) doc;
        int whatToShow = NodeFilter.SHOW_ELEMENT;
        NodeIterator iterator = traversable.createNodeIterator(doc, whatToShow, filter, true);
        Node current = null;/*from   w  w w  . ja v  a 2  s  .  co  m*/
        while ((current = iterator.nextNode()) != null) {
            result.add((Element) current);
        }
        return result;
    }
}

Related

  1. getElementAsFloat(Element e, String name, Float dft)
  2. getElementAsInt(Element element)
  3. getElementAttributeValue(Document doc, String tagName, String attributeName)
  4. getElementBooleanValue(Document document, Element parent, String element)
  5. getElementByClass(Element ele, String name)
  6. getElementByID(Element el, String id)
  7. getElementByID(Element el, String id)
  8. getElementById(Element element, String id)
  9. getElementByName(Element ele, String name)