use of org.jsoup.nodes.Document in project jsoup by jhy.
the class ElementsTest method is.
@Test
public void is() {
String h = "<p>Hello<p title=foo>there<p>world";
Document doc = Jsoup.parse(h);
Elements ps = doc.select("p");
assertTrue(ps.is("[title=foo]"));
assertFalse(ps.is("[title=bar]"));
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class ElementsTest method wrapDiv.
@Test
public void wrapDiv() {
String h = "<p><b>This</b> is <b>jsoup</b>.</p> <p>How do you like it?</p>";
Document doc = Jsoup.parse(h);
doc.select("p").wrap("<div></div>");
assertEquals("<div><p><b>This</b> is <b>jsoup</b>.</p></div> <div><p>How do you like it?</p></div>", TextUtil.stripNewlines(doc.body().html()));
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class ElementsTest method unwrap.
@Test
public void unwrap() {
String h = "<div><font>One</font> <font><a href=\"/\">Two</a></font></div";
Document doc = Jsoup.parse(h);
doc.select("font").unwrap();
assertEquals("<div>One <a href=\"/\">Two</a></div>", TextUtil.stripNewlines(doc.body().html()));
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class XmlTreeBuilderTest method testDoesHandleEOFInTag.
@Test
public void testDoesHandleEOFInTag() {
String html = "<img src=asdf onerror=\"alert(1)\" x=";
Document xmlDoc = Jsoup.parse(html, "", Parser.xmlParser());
assertEquals("<img src=\"asdf\" onerror=\"alert(1)\" x=\"\" />", xmlDoc.html());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class XmlTreeBuilderTest method testCreatesValidProlog.
@Test
public void testCreatesValidProlog() {
Document document = Document.createShell("");
document.outputSettings().syntax(Syntax.xml);
document.charset(Charset.forName("utf-8"));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<html>\n" + " <head></head>\n" + " <body></body>\n" + "</html>", document.outerHtml());
}
Aggregations