我正在为我正在构建的 Android 应用程序使用 google books api。这是 XML 文件的示例
<dc:description>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 ...</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 " The Hitchhiker's Guide to the Galaxy" , " TheRestaurant at the End of the Universe" , " Life, Universe and Everything" and " So Long ...
如果我随后手动将其添加到应用程序中,HTML.fromHtml() 工作正常,所以我猜问题是 Android 的解析器实现。
一个类似的问题是Android 在 xml 文件中解码 html。我尝试将工厂的验证设置为 false,并且由于它是 RSS 提要,我无法声明 HTML 根元素(如本文中所建议的那样)。