Java tutorial
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * Gets a attribute value. * * @param pNode * the p node * @param pAttributeName * the p attribute name * @return the attribute value */ public static String getAttributeValue(Node pNode, String pAttributeName) { String returnString = null; NamedNodeMap attributes = pNode.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { if (attributes.item(i).getNodeName().equalsIgnoreCase(pAttributeName)) { returnString = attributes.item(i).getNodeValue(); break; } } } return returnString; } /** * Gets a node value. * * @param pNode * the p node * @return the node value */ public static String getNodeValue(Node pNode) { if (pNode.getNodeValue() != null) { return pNode.getNodeValue(); } else if (pNode.getFirstChild() != null) { return getNodeValue(pNode.getFirstChild()); } else { return null; } } }