Here you can find the source of appendAllAttributes(Node node, StringBuffer xpath)
public static void appendAllAttributes(Node node, StringBuffer xpath)
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static void appendAllAttributes(Node node, StringBuffer xpath) { NamedNodeMap attr = node.getAttributes(); int len = attr.getLength(); if (len > 0) { for (int i = 0; i < len; i++) { Node item = attr.item(i); xpath.append("[@"); xpath.append(item.getNodeName()); xpath.append("='"); xpath.append(item.getNodeValue()); xpath.append("']"); }/* w w w . j a va 2 s . co m*/ } } /** * Utility method to fetch the value of the element node * * @param node * @return */ public static String getNodeValue(Node node) { for (Node child = node.getFirstChild(); child != null; child = child .getNextSibling()) { if (child.getNodeType() == Node.TEXT_NODE) { return child.getNodeValue(); } } return null; } }