I have made little test (with Jsoup 1.6.1):
String s = \"\" +Jsoup.parse(\" \").select(\"td\").size();
System.out.println(\"Selected elements
Jsoup 1.6.2 allows to parse with different parser and simple XML parser is provided. With following code I could solve my problem. You can later parse your fragment with HTML parse, to get valid HTML.
// Jsoup 1.6.2
String s = "" + Jsoup.parse("<td></td>", "", Parser.xmlParser()).select("td").size();
System.out.println("Selected elements count : " + s);
Because Jsoup is a HTML5 compliant parser and you feeded it with invalid HTML. A <td>
has to go inside at least a <table>
.
int size = Jsoup.parse("<table><td></td></table>").select("td").size();
System.out.println("Selected elements count : " + size);
String url = "http://foobar.com";
Document doc = Jsoup.connect(url).get();
Elements td = doc.select("td");