use of org.jsoup.nodes.Document in project jsoup by jhy.
the class ElementsTest method attr.
@Test
public void attr() {
Document doc = Jsoup.parse("<p title=foo><p title=bar><p class=foo><p class=bar>");
String classVal = doc.select("p").attr("class");
assertEquals("foo", classVal);
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class ElementsTest method remove.
@Test
public void remove() {
Document doc = Jsoup.parse("<div><p>Hello <b>there</b></p> jsoup <p>now!</p></div>");
doc.outputSettings().prettyPrint(false);
doc.select("p").remove();
assertEquals("<div> jsoup </div>", doc.body().html());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class ElementsTest method traverse.
@Test
public void traverse() {
Document doc = Jsoup.parse("<div><p>Hello</p></div><div>There</div>");
final StringBuilder accum = new StringBuilder();
doc.select("div").traverse(new NodeVisitor() {
public void head(Node node, int depth) {
accum.append("<" + node.nodeName() + ">");
}
public void tail(Node node, int depth) {
accum.append("</" + node.nodeName() + ">");
}
});
assertEquals("<div><p><#text></#text></p></div><div><#text></#text></div>", accum.toString());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class ElementsTest method filter.
@Test
public void filter() {
String h = "<p>Excl</p><div class=headline><p>Hello</p><p>There</p></div><div class=headline><h1>Headline</h1></div>";
Document doc = Jsoup.parse(h);
Elements els = doc.select(".headline").select("p");
assertEquals(2, els.size());
assertEquals("Hello", els.get(0).text());
assertEquals("There", els.get(1).text());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class ElementsTest method hasText.
@Test
public void hasText() {
Document doc = Jsoup.parse("<div><p>Hello</p></div><div><p></p></div>");
Elements divs = doc.select("div");
assertTrue(divs.hasText());
assertFalse(doc.select("div + div").hasText());
}
Aggregations