Exemple #1
0
  @Test
  public void testOutputEncoding() {
    Document doc = Jsoup.parse("<p title=π>π & < > </p>");
    // default is utf-8
    assertEquals("<p title=\"π\">π &amp; &lt; &gt; </p>", doc.body().html());
    assertEquals("UTF-8", doc.outputSettings().charset().displayName());

    doc.outputSettings().charset("ascii");
    assertEquals(Entities.EscapeMode.base, doc.outputSettings().escapeMode());
    assertEquals("<p title=\"&#x3c0;\">&#x3c0; &amp; &lt; &gt; </p>", doc.body().html());

    doc.outputSettings().escapeMode(Entities.EscapeMode.extended);
    assertEquals("<p title=\"&pi;\">&pi; &amp; &lt; &gt; </p>", doc.body().html());
  }
Exemple #2
0
 @Test
 public void testXhtmlReferences() {
   Document doc = Jsoup.parse("&lt; &gt; &amp; &quot; &apos; &times;");
   doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
   assertEquals("&lt; &gt; &amp; &quot; &apos; ×", doc.body().html());
 }