Search in sources :

Example 36 with Document

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()));
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 37 with Document

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());
}
Also used : XmlDeclaration(org.jsoup.nodes.XmlDeclaration) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 38 with Document

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());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 39 with Document

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));
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 40 with Document

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());
}
Also used : Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Aggregations

Document (org.jsoup.nodes.Document)405 Test (org.junit.Test)194 Element (org.jsoup.nodes.Element)164 IOException (java.io.IOException)102 File (java.io.File)81 Elements (org.jsoup.select.Elements)78 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)51 ArrayList (java.util.ArrayList)41 Connection (org.jsoup.Connection)38 URL (java.net.URL)25 HashMap (java.util.HashMap)17 InputStream (java.io.InputStream)14 List (java.util.List)10 MalformedURLException (java.net.MalformedURLException)8 Logger (org.slf4j.Logger)8 Matcher (java.util.regex.Matcher)7 Jsoup (org.jsoup.Jsoup)7 LoggerFactory (org.slf4j.LoggerFactory)7 Pattern (java.util.regex.Pattern)6 HttpGet (org.apache.http.client.methods.HttpGet)6