Java tutorial
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { /** * Get the attribute value of a given attribute name for * the first XML {@code org.w3c.dom.Element} of given name. * * @param elem the parent XML Element * @param name the name of the child text Element * @param attrName the attribute name * @return attribute value of named child Element */ public static String getFirstAttribute(Element elem, String name, String attrName) { NodeList nodeList = elem.getElementsByTagName(name); if (nodeList.getLength() == 0) { return null; } return (((Element) nodeList.item(0)).getAttribute(attrName)); } }