0

我正在为我正在构建的 Android 应用程序使用 google books api。这是 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 提要,我无法声明 HTML 根元素(如本文中所建议的那样)。

4

1 回答 1

0

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

于 2011-02-24T08:42:48.940 回答