use of org.jsoup.nodes.Document in project jsoup by jhy.
the class XmlTreeBuilderTest method canNormalizeCase.
@Test
public void canNormalizeCase() {
String xml = "<TEST ID=1>Check</TEST>";
Document doc = Jsoup.parse(xml, "", Parser.xmlParser().settings(ParseSettings.htmlDefault));
assertEquals("<test id=\"1\">Check</test>", TextUtil.stripNewlines(doc.html()));
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class XmlTreeBuilderTest method testParseDeclarationAttributes.
@Test
public void testParseDeclarationAttributes() {
String xml = "<?xml version='1' encoding='UTF-8' something='else'?><val>One</val>";
Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
XmlDeclaration decl = (XmlDeclaration) doc.childNode(0);
assertEquals("1", decl.attr("version"));
assertEquals("UTF-8", decl.attr("encoding"));
assertEquals("else", decl.attr("something"));
assertEquals("version=\"1\" encoding=\"UTF-8\" something=\"else\"", decl.getWholeDeclaration());
assertEquals("<?xml version=\"1\" encoding=\"UTF-8\" something=\"else\"?>", decl.outerHtml());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class XmlTreeBuilderTest method caseSensitiveDeclaration.
@Test
public void caseSensitiveDeclaration() {
String xml = "<?XML version='1' encoding='UTF-8' something='else'?>";
Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
assertEquals("<?XML version=\"1\" encoding=\"UTF-8\" something=\"else\"?>", doc.outerHtml());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class CleanerTest method testIsValidDocument.
@Test
public void testIsValidDocument() {
String ok = "<html><head></head><body><p>Hello</p></body><html>";
String nok = "<html><head><script>woops</script><title>Hello</title></head><body><p>Hello</p></body><html>";
Whitelist relaxed = Whitelist.relaxed();
Cleaner cleaner = new Cleaner(relaxed);
Document okDoc = Jsoup.parse(ok);
assertTrue(cleaner.isValid(okDoc));
assertFalse(cleaner.isValid(Jsoup.parse(nok)));
assertFalse(new Cleaner(Whitelist.none()).isValid(okDoc));
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class CleanerTest method handlesFramesets.
@Test
public void handlesFramesets() {
String dirty = "<html><head><script></script><noscript></noscript></head><frameset><frame src=\"foo\" /><frame src=\"foo\" /></frameset></html>";
String clean = Jsoup.clean(dirty, Whitelist.basic());
// nothing good can come out of that
assertEquals("", clean);
Document dirtyDoc = Jsoup.parse(dirty);
Document cleanDoc = new Cleaner(Whitelist.basic()).clean(dirtyDoc);
assertFalse(cleanDoc == null);
assertEquals(0, cleanDoc.body().childNodeSize());
}
Aggregations