Java XML Attribute from Element getElementAttribute(Element root, String elementName, String attribute)

Here you can find the source of getElementAttribute(Element root, String elementName, String attribute)

Description

get Element Attribute

License

GNU General Public License

Declaration

public static String getElementAttribute(Element root,
        String elementName, String attribute) 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 * Version: GPL 2.0//from w  w  w .ja v  a 2 s .  com
 *
 * The contents of this file are subject to the GNU General Public
 * License Version 2 or later (the "GPL").
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Initial Developer of the Original Code is
 *   MiniG.org project members
 *
 * ***** END LICENSE BLOCK ***** */

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Main {

    public static String getElementAttribute(Element root,
            String elementName, String attribute) {
        NodeList list = root.getElementsByTagName(elementName);
        if (list.getLength() == 0) {
            return null;
        }
        return ((Element) list.item(0)).getAttribute(attribute);
    }
}

Related

  1. getElement(Element root, String tagName, String attrName, String attrValue)
  2. getElementArrayInt(Element root, String name, String attrib)
  3. getElementArrayString(Element root, String name, String attrib)
  4. getElementAttr(Element element, String attr)
  5. getElementAttribute(Element element, String name)
  6. getElementAttribute(Element root, String elemName, String att)
  7. getElementAttributes(Element element, List exclude)
  8. getElementAttributeValue(Element element, String attributeName)
  9. getElementBooleanValue(Element element, String attribute)