Here you can find the source of getFirstAttribute(Element elem, String name, String attrName)
Parameter | Description |
---|---|
elem | the parent XML Element |
name | the name of the child text Element |
attrName | the attribute name |
public static String getFirstAttribute(Element elem, String name, String attrName)
//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 { /**/*from w w w . ja v a 2 s.c o m*/ * 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)); } }