Java XML Element Get getElementWithKeyFromDocument(final Document document, final String key)

Here you can find the source of getElementWithKeyFromDocument(final Document document, final String key)

Description

get Element With Key From Document

License

Open Source License

Declaration

public static Element getElementWithKeyFromDocument(final Document document, final String key) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    public static Element getElementWithKeyFromDocument(final Document document, final String key) {
        final NodeList nodeList = document.getElementsByTagName(key);
        Element result = null;//from   ww w .  j a va  2 s. c  o m
        if (nodeList.getLength() > 0) {
            result = (Element) nodeList.item(0);
        }
        return result;
    }
}

Related

  1. getElementsByTagNameNS1(Element element, String nsName, String tagName)
  2. getElementsByTagNameNS1(Element element, String nsName, String tagName)
  3. getElementsByXpath(Document docInput, String xPath)
  4. getElementsWithName(Document doc, String name)
  5. getElementText(Document owner, String elementName, String nsURI)