使用Jsoup保持换行符

时间:2015-04-21 09:05:01

标签: java apache-poi jsoup

我有一个.docx文档,如下所示:

1. Part One
   Some <message>xml</message> text
2. Part Two
   Some plain text

我想获取纯文本内容并删除所有xml标签。 因此我使用Apache poi和Jsoup:

XWPFDocument docx = new XWPFDocument(new FileInputStream(path));
XWPFWordExtractor wordxExtractor = new XWPFWordExtractor(docx);
String content = wordxExtractor.getText();
System.out.println(content);
content = Jsoup.parse(content).text();
System.out.println(content);

打印:

Part One
Some <message>xml</message> text
Part Two
Some plain text 

Part One Some xml text Part Two Some plain text

现在的问题是: 在xml解析之后,换行符不再出现 - 我怎么能避免这种情况(我想保留换行符)?

0 个答案:

没有答案
相关问题