Java XML Attribute Get getAttribute(Node node, String attr)

Here you can find the source of getAttribute(Node node, String attr)

Description

Get the value of a specific attribute on an XML node

License

Open Source License

Parameter

Parameter Description
node - the XML node that contains the attribute.
attr - the name of the attribute

Return

- a node containing the attribute.

Declaration

public static Node getAttribute(Node node, String attr) 

Method Source Code

//package com.java2s;
/*//  w  w  w.ja va 2  s .  co m
 * Copyright 2014 Carnegie Mellon University
 * 
    
 * Any opinions, findings and conclusions or recommendations expressed in this 
 * Material are those of the author(s) and do not necessarily reflect the 
 * views of the United States Department of Defense. 
    
 * NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING 
 * INSTITUTE MATERIAL IS FURNISHED ON AN ?AS-IS? BASIS. CARNEGIE MELLON 
 * UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, 
 * AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR 
 * PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF 
 * THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF 
 * ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT 
 * INFRINGEMENT.
 * 
 * This Material has been approved for public release and unlimited 
 * distribution except as restricted below. 
 * 
 * This Material is provided to you under the terms and conditions of the 
 * Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is 
 * provided with this Content and is also available at 
 * http://www.eclipse.org/legal/epl-v10.html.
 * 
 * Carnegie Mellon is registered in the U.S. Patent and Trademark 
 * Office by Carnegie Mellon University. 
 * 
 */

import org.w3c.dom.Node;

public class Main {
    /**
     * Get the value of a specific attribute on an XML node
     * @param node  - the XML node that contains the attribute.
     * @param attr  - the name of the attribute
     * @return      - a node containing the attribute.
     */
    public static Node getAttribute(Node node, String attr) {
        return node.getAttributes().getNamedItem(attr);
    }
}

Related

  1. getAttribute(Node n, String attr)
  2. getAttribute(Node n, String attr, String def)
  3. getAttribute(Node n, String name)
  4. getAttribute(Node node, String att_name)
  5. getAttribute(Node node, String attName, boolean domLevel3)
  6. getAttribute(Node node, String attr)
  7. getAttribute(Node node, String attr)
  8. getAttribute(Node node, String attr)
  9. getAttribute(Node node, String attribName)