Here you can find the source of getAttributeValue(Node node, String name)
Parameter | Description |
---|---|
node | the node. |
name | the attribute. |
public static String getAttributeValue(Node node, String name)
//package com.java2s; /*--------------------------------------------------------------- * Copyright 2005 by the Radiological Society of North America * * This source software is released under the terms of the * RSNA Public License (http://mirc.rsna.org/rsnapubliclicense) *----------------------------------------------------------------*/ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /**/*ww w . j ava 2s . c o m*/ * Get the value of a node's attribute. If the node is a Document, use the * document element as the element node. * @param node the node. * @param name the attribute. * @return the value of the attribute, or an empty string if the * node is not an element or the attribute is missing. */ public static String getAttributeValue(Node node, String name) { if (node instanceof Document) node = ((Document) node).getDocumentElement(); if (!(node instanceof Element)) return ""; return ((Element) node).getAttribute(name); } }