java - 如何解析/格式化充满 CSS 代码的 RSS 标签

标签 java android css xml rss

我正在使用以下 RSS:http://aplicaciones.esi.us.es/antalumnos/rss.xml

正如我们所见,description 标签包含了我需要的文本,并且在文本之间充满了 CSS 代码。这是一个问题,因为一旦我解析了描述标签,我也会得到所有的 CSS 代码。

RSS 链接是用 drupal 6 制作的,无法更改,此外其他 RSS 阅读器如 feedly 可以完美显示所有内容,文本之间无需代码。我该如何处理这个问题?

   <description>
&lt;p&gt;&amp;nbsp;&lt;span style=&quot;color: rgb(51, 51, 51); font-family: Verdana, Geneva, sans-serif; font-size: 13.3333px; background-color: rgb(255, 255, 255);&quot;&gt;El pasado sábado 11 de Junio cerramos la temporada de rutas en bici organizadas por la Asociación con un recorrido de 72 Km por la conocida y espectacular Vía Verde de la Sierra. Con un día soleado y no excesivamente caluroso partimos con nuestras máquinas desde la estación de Puerto Serrano en dirección a Olvera, disfrutando de un bello y rico entorno natural fuimos avanzando con paradas en los sitios más singulares (Chaparro de la Vega, estación de Coripe, Peñón de Zaframagón y estación de Olvera. Una vez aquí retornamos al punto de partida.&lt;/span&gt;&lt;/p&gt;
&lt;div style=&quot;padding-top: 0px; border-top-width: 0px; color: rgb(51, 51, 51); font-family: Verdana, Geneva, sans-serif; font-size: 13.3333px; background-color: rgb(255, 255, 255);&quot;&gt;
&lt;p&gt;A pesar de la distancia recorrida la ruta se hizo llevadera gracias a la coincidencia de varios factores como la buena compañía, la belleza del entorno, un buen firme parq rodar sin muchos desniveles y con treinta túneles en los que refrescarse a su paso.&lt;/p&gt;
&lt;p&gt;Finalmente en el restaurante de la estación de Puerto Serrano compartimos, como de costumbre, un agradable rato para reponer energías degustando los productos de la zona.&lt;/p&gt;
&lt;p&gt;Facilitamos algunas fotos:&lt;/p&gt;
&lt;/div&gt;
&lt;div style=&quot;color: rgb(51, 51, 51); font-family: Verdana, Geneva, sans-serif; font-size: 13.3333px; background-color: rgb(255, 255, 255);&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;color: rgb(51, 51, 51); font-family: Verdana, Geneva, sans-serif; font-size: 13.3333px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a title=&quot;http://aplicaciones.esi.us.es/antalumnos/node/3144&quot; href=&quot;http://aplicaciones.esi.us.es/antalumnos/node/3144&quot; target=&quot;_blank&quot; rel=&quot;noreferrer&quot; style=&quot;color: rgb(1, 134, 186);&quot;&gt;http://aplicaciones.esi.us.es/antalumnos/node/3144&lt;/a&gt;&lt;/div&gt;
</description>

最佳答案

替换所有出现的 style=... 的最佳方法是使用正则表达式 (regex),我认为这是您要删除的 CSS 代码部分。我用这个site作为引用。这是一个小例子:

String text = "style=&quot;hfhdjdh;&quot; YAY";
String regex = "(style=&quot;)(.*)(&quot;)";
System.out.println(text.replaceAll(regex, "replaced"));

这将输出 replaced YAY。本质上,就像我的评论一样,正则表达式找到了 style=" 的地方,(.*) 忽略了里面的任何东西,我们用另一个 " 标记结束。您只需要用空格或空字符串更改替换字符串,它就会将其从您的内容中删除。 replaceAll 应该删除所有出现的地方,因此您不需要逐行搜索。

关于java - 如何解析/格式化充满 CSS 代码的 RSS 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38065181/

相关文章:

android - 在 kotlin 中创建 LayerDrawable 时发生类转换异常

带有 true/false 结果的 Java 单行异常处理

java - 如何从 JBoss 5.x 下的 JavaEE 应用程序获取类加载器 ObjectName

android - ActionbarCompat 的 MultiChoiceAdapter NoSuchMethodException : startActionMode

html - animate.css:如何让 css 动画只在第一次运行?

css - 变换 :translateZ(0) animation explanation

html - 如何使用属性将 css 定义为表 td?

java - 如何使用三元运算符隐藏和显示 Textview

java - java中十进制数的奇怪正则表达式行为

Android 操作栏溢出图标不可见