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
    }
}

输出:

===============================================
<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>

由于 JSoup 进行了格式化,textNodes 的值更改为包含换行符。

在测试用例中更改<inline>为似乎工作正常,但不幸的是,我们有包含由 redactor 生成的标签的遗留数据/html。<span><inline>

4

1 回答 1

1

试试这个:

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

希望能帮助到你。

取自https://stackoverflow.com/a/19602313/3324704

于 2014-11-10T13:03:32.953 回答