0
String testCases[] = {
        "<table><tbody><tr><td><div><inline>Normal Line Text</inline><br/></div></td></tr></tbody></table>",                  
};
for (String testString : testCases) {
    Document doc = Jsoup.parse(testString,"", Parser.xmlParser());
    Elements elements = doc.select("table");
    for (Element ele : elements) {
        System.out.println("===============================================");
        System.out.println(ele.html());                //Formatted
        System.out.println("-----------------------------------------------");
        System.out.println(ele.html().trim().replace("\n","").replace("\r",""));    //Notice the Difference
    }
}

Output:

===============================================
<tbody>
 <tr>
  <td>
   <div>
    <inline>
     Normal Line Text
    </inline>
    <br />
   </div></td>
 </tr>
</tbody>
-----------------------------------------------
<tbody> <tr>  <td>   <div>    <inline>     Normal Line Text    </inline>    <br />   </div></td> </tr></tbody>

Due to the formatting done by JSoup, the value of textNodes change to include newlines.

Changing <inline> to <span> in the test case seems to work fine, but unfortunately, we have legacy data/html containing <inline> tags generated by redactor.

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
coding_idiot
  • 13,526
  • 10
  • 65
  • 116

1 Answers1

2

Try this:

Document doc = Jsoup.parse(testString,"", Parser.xmlParser());
doc.outputSettings().prettyPrint(false);

Hope it helps.

Taken from https://stackoverflow.com/a/19602313/3324704

Community
  • 1
  • 1
fonkap
  • 2,469
  • 1
  • 14
  • 30