Java tutorial
//package com.java2s; import java.util.*; import org.w3c.dom.*; public class Main { /** * Returns whether the given XML DOM node contains the given attribute. * @param node the XML node to examine * @param name an attribute name to check * @return true if the attribute exists, false if not */ public static boolean hasAttribute(Node node, String name) { return node.getAttributes().getNamedItem(name) != null; } /** * Returns all attributes of the given XML node as a list of name=value strings. * Mostly just for debugging. * @param node * @return */ public static List<String> getAttributes(Node node) { List<String> result = new ArrayList<String>(); NamedNodeMap attrs = node.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attrNode = attrs.item(i); result.add(attrNode.getNodeName() + "=" + attrNode.getNodeValue()); } return result; } }