java - 如何解析 XML 标签中的换行符?

标签 java android parsing dom xml-parsing

我正在解析 RSS 提要,其中 <description> 标签包含一些像这样的\n 行字符

    <?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<item>
      <guid>http://www.horseandhound.co.uk/blogs/7619/314307.html</guid>
      <title>Chloe Chubb&#039;s s<title>Chloe Chubb&#039;s showing blog: Horse of the Year Show (HOYS) preparations</title>
      <description>So it is a week before HOYS and I have somehow managed to stay a bit oblivious to it all. It is only when I log onto Facebook and see the many, many statuses talking about it that I realise it’s only just around the corner! Then the butterflies begin.
&lt;br /&gt;
 /&gt;
My pre-HOYS diet was going well until last weekend when me and my best mates headed for a weekend away by the beach. Cue huge amounts of cheese, wine and cake and with the 5 pounds I’d lost, 2 went straight back on.&amp;#8230;</description>
      <url>http://www.horseandhound.co.uk/blogs/7619/314307.html</url>
</item>
</channel>
</rss>

在这里,我能够解析第一行“some text in line1..”之前的文本,但从下一行开始,剩余的文本不会被解析。我正在使用 Dom 解析器。请建议如何解决此问题。

最佳答案

您可以使用实体 来表示 XML 属性中的换行符。
可用于表示回车。
Windows 风格的 CRLF 可以表示为

参见XML spec了解更多详情。

关于java - 如何解析 XML 标签中的换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12853239/

相关文章:

java - 如何使用 Android setTranslation ? (或另一种移动 TextView 的方法?)

java - 透明 Java 窗口上的不透明组件

java - 无法解析符号

java - 谷歌地点 API 的 GSON 解析

java - 什么是NullPointerException,我该如何解决?

android - 如何在通知上显示计时器?

android - 为什么 ACTION_DOWN 可能偶尔不会在 Android 中为 ListView 触发

java - 当单击 ListView 中的选择项时,没有任何反应,但 LogCat 中没有错误

php - PHP 中的 URL 解析和简化

java - DateTimeFormatter 在解析个位数部分时过于严格