Java XML Attribute Get getAttribute(Element ownerElem, String attrName)

Here you can find the source of getAttribute(Element ownerElem, String attrName)

Description

Gets an attribute value of the given element.

License

Open Source License

Parameter

Parameter Description
ownerElem the element that owns the attribute
attrName the name of the attribute to retrieve

Return

the attribute value as a string, or null if that attribute does not have a specified value

Declaration

public static String getAttribute(Element ownerElem, String attrName) 

Method Source Code

//package com.java2s;
/*/*from  w ww  . jav a 2 s  .  c  o m*/
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
 * published by JBoss Inc.; either version 1.0 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

import org.w3c.dom.Attr;

import org.w3c.dom.Element;

public class Main {
    /**
     * Gets an attribute value of the given element.
     * @param ownerElem the element that owns the attribute
     * @param attrName the name of the attribute to retrieve
     * @return the attribute value as a string, or <code>null</code> if that attribute does not have
     * a specified value
     */
    public static String getAttribute(Element ownerElem, String attrName) {
        Attr attribute = ownerElem.getAttributeNode(attrName);
        return attribute != null ? attribute.getValue() : null;
    }
}

Related

  1. getAttribute(Element element, String name)
  2. getAttribute(Element element, String name)
  3. getAttribute(Element element, String name, String defaultVal)
  4. getAttribute(Element element, String namespace, String name)
  5. getAttribute(Element element, String nodeName)
  6. getAttribute(Element parent, String localName)
  7. getAttribute(Element parent, String localName, String namespaceURI)
  8. getAttribute(File file, String attr)
  9. getAttribute(final List elements, final int index)