繁体   English   中英

Android使用DOM解析器解析RSS提要的HTML实体

[英]Android parsing HTML entities using DOM parser for RSS feed

我正在将Google Books API用于正在构建的Android应用。 这是XML文件的示例

<dc:description>This trilogy includes &amp;quot; The Hitchhiker&amp;#39;s Guide to the Galaxy&amp;quot; , &amp;quot; TheRestaurant at the End of the Universe&amp;quot; , &amp;quot; Life, Universe and Everything&amp;quot; and &amp;quot; So Long ...</dc:description>
<dc:format>590 pages</dc:format>
<dc:format>book</dc:format>

这只是我用来提取描述的一部分代码

if ( entry.getElementsByTagName( "dc:description" ).item( 0 ) != null ) {
  Element d = ( Element ) entry.getElementsByTagName( "dc:description" )
      .item( 0 );
  b.setDescription( d.getFirstChild( ).getNodeValue( ) );

}

问题是,当使用HTML.fromHtml(Str)函数时,它将在第一个HTML实体处截断文本(因此,在此示例中,它仅表示

这三部曲包括

当我在Android外部运行相同的代码时,它可以正常工作,并且至少显示带有转义字符的字符串,即

This trilogy includes &quot; The Hitchhiker&#39;s Guide to the Galaxy&quot; , &quot; TheRestaurant at the End of the Universe&quot; , &quot; Life, Universe and Everything&quot; and &quot; So Long ...

如果我随后将其手动添加到应用程序中,则HTML.fromHtml()可以正常工作,因此我想问题是Android的解析器实现。

一个类似的问题是Android解码xml文件中的html 我尝试将工厂的验证设置为false,并且由于它是RSS feed,因此我无法声明HTML根元素(如本文所建议)。

我最终没有从Google获得描述数据,但是我认为可以通过在document元素上运行normalise()来解决该问题-我在另一个API上也遇到了类似的问题,并对其进行了修复。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM