Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Vector;

import org.w3c.dom.*;

public class Main {
    public static Vector getElementsByTagAndAttribValue(org.w3c.dom.Element element, String tag, String attrib,
            String val) {
        NodeList desElements = element.getElementsByTagName(tag);
        Vector selElements = new Vector(desElements.getLength() / 10, 10);

        for (int i = 0; i < desElements.getLength(); i++) {
            org.w3c.dom.Node desElement = desElements.item(i);

            if (desElement.getNodeType() == org.w3c.dom.Element.ELEMENT_NODE) {
                NamedNodeMap attributeNodes = desElement.getAttributes();

                org.w3c.dom.Node selAttribNode = attributeNodes.getNamedItem(attrib);

                if (selAttribNode != null && selAttribNode.getNodeValue().equalsIgnoreCase(val)) {
                    selElements.add(desElement);
                }
            }
        }

        return selElements;
    }
}