Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { private static boolean equalElements(final Element a, final Element b) { if (!a.getTagName().equals(b.getTagName())) { return false; } final NamedNodeMap attributes = a.getAttributes(); int customAttributeCounter = 0; for (int i = 0, n = attributes.getLength(); i < n; i++) { final Node node = attributes.item(i); if (node != null && !node.getNodeName().startsWith("_")) { if (!node.getNodeName().equals("z") && (b.getAttribute(node.getNodeName()).length() == 0 || !b.getAttribute(node.getNodeName()).equals(node.getNodeValue()))) { return false; } } else { customAttributeCounter++; } } if (a.getAttributes().getLength() - customAttributeCounter != b.getAttributes().getLength()) { return false; } return true; } }