Java XML Element Get by ID getElementById(Document dom, String id, String localElementName)

Here you can find the source of getElementById(Document dom, String id, String localElementName)

Description

get Element By Id

License

Open Source License

Declaration

public static Element getElementById(Document dom, String id,
            String localElementName) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

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

import org.w3c.dom.NodeList;

public class Main {
    public static Element getElementById(Document dom, String id,
            String localElementName) {

        NodeList children = dom.getElementsByTagNameNS(
                "*", localElementName); //$NON-NLS-1$
        for (int i = 0; i < children.getLength(); i++) {
            Element element = (Element) children.item(i);
            if (element.getAttribute("id").equals(id)) {
                return element;
            }//  ww  w  .j av a2  s .c o m
        }
        // non found.
        return null;

    }
}

Related

  1. getElemenById(Document document, String elementId)
  2. getElementById(Document doc, String id, Map idMap)
  3. getElementById(Document document, String id)
  4. getElementById(Document dom, String id)