Java tutorial
//package com.java2s; import org.w3c.dom.Element; public class Main { /** * Returns {@code true} if the element matches the filters. * * @param elem * @param filters * @return */ private static boolean matchesFilters(Element elem, String... filters) { for (String filter : filters) { final String attribute = extractFilterName(filter); final String value = extractFilterValue(filter); if (!elem.getAttribute(attribute).equals(value)) { return false; } } return true; } /** * Convenience method to extract name from {@code @fooAttribute="blagh"} * style filter. * * @param filter * @return */ private static String extractFilterName(String filter) { if (filter.startsWith("@")) { return filter.substring(1, filter.indexOf("=")); } else if (filter.startsWith(".")) { // means this element, so return null return null; } else { return filter.substring(0, filter.indexOf("=")); } } /** * Convenience method to extract value from {@code @fooAttribute="blagh"} * style filter. * * @param filter * @return */ private static String extractFilterValue(String filter) { return filter.substring(filter.indexOf("=\"") + 2, filter.lastIndexOf("\"")); } }