Here you can find the source of getAttribute(Node node, String attributeName)
Parameter | Description |
---|---|
node | a parameter |
attributeName | a parameter |
public static String getAttribute(Node node, String attributeName)
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /**//from w w w. ja va 2 s.c om * A safe way of getting attribute value of attribute with given name. If attribute with given name * doesn't exist, returns null * (instead of NPE). * * @param node * @param attributeName * @return */ public static String getAttribute(Node node, String attributeName) { if (node == null) return null; NamedNodeMap attributes = node.getAttributes(); if (attributes == null) return null; Node attribute = attributes.getNamedItem(attributeName); if (attribute == null) return null; return attribute.getTextContent(); } }