Here you can find the source of getElementById(Document dom, String id)
public static Element getElementById(Document dom, String id)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/* w ww .jav a2 s. c o m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ 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)) //$NON-NLS-1$ return element; } // non found. return null; } public static Element getElementById(Document dom, String id) { return getElementById(dom, id, "*"); //$NON-NLS-1$ } }