Here you can find the source of getAttribute(Node node, String name)
Parameter | Description |
---|---|
node | the XML node which contain the attribute |
name | the name of the attrbiute |
public static String getAttribute(Node node, String name)
//package com.java2s; /*L//from w w w. j av a 2 s. c o m * Copyright SAIC, SAIC-Frederick. * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/caadapter/LICENSE.txt for details. */ import org.w3c.dom.Attr; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * This method will get the value of an attribute for a given node * * @param node the XML node which contain the attribute * @param name the name of the attrbiute * @return String the string value of the attribute. */ public static String getAttribute(Node node, String name) { NamedNodeMap attrs = node.getAttributes(); if (attrs == null) return null; Attr attr = (Attr) attrs.getNamedItem(name); if (attr == null) return null; else return attr.getNodeValue(); } }