Rectangle 27 0

java Jsoup getting a HTML tag with ONLY the specified attributes and its values?


Document doc = Jsoup.parse(
    "<table width=100% cellpadding=0 cellspacing=0>OK</table>" +
    "<table width=100% cellpadding=0 cellspacing=0 height=100%>NO</table>");

for (Element el: doc.select("table[width=100%][cellpadding=0][cellspacing=0]"))
    if (el.attributes().size() == 3)
        System.out.println(el.text());
OK
for (Element el: doc.select("table[width=100%][cellpadding=0][cellspacing=0]"))
    if (el.attributes().size() == 3)
        // Do something

Your selector already select element having a specific value for those 3 attributes. So the element has at least 3 attributes. But if it has exactly 3 attributes, then those are the ones you specified.

hahaha! simple technique! just messing around with the basics and there you go a wonderful solution! i should have thought of this myself!! well, thanks a lot!! just learning so many new things!! thanks a lot!

Note