Search in sources :

Example 1 with HtmlTreeBuilder

use of org.jsoup.parser.HtmlTreeBuilder in project jsoup by jhy.

the class UrlConnectTest method fetchHandlesXmlAsHtmlWhenParserSet.

@Test
public void fetchHandlesXmlAsHtmlWhenParserSet() throws IOException {
    // should auto-detect xml and use XML parser, unless explicitly requested the html parser
    String xmlUrl = "http://direct.infohound.net/tools/parse-xml.xml";
    Connection con = Jsoup.connect(xmlUrl).parser(Parser.htmlParser());
    Document doc = con.get();
    Connection.Request req = con.request();
    assertTrue(req.parser().getTreeBuilder() instanceof HtmlTreeBuilder);
    assertEquals("<html> <head></head> <body> <xml> <link>one <table> Two </table> </xml> </body> </html>", StringUtil.normaliseWhitespace(doc.outerHtml()));
}
Also used : HtmlTreeBuilder(org.jsoup.parser.HtmlTreeBuilder) Connection(org.jsoup.Connection) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Aggregations

Connection (org.jsoup.Connection)1 Document (org.jsoup.nodes.Document)1 HtmlTreeBuilder (org.jsoup.parser.HtmlTreeBuilder)1 Test (org.junit.Test)1