[英]Android parsing HTML entities using DOM parser for RSS feed
我正在將Google Books API用於正在構建的Android應用。 這是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 feed,因此我無法聲明HTML根元素(如本文所建議)。
我最終沒有從Google獲得描述數據,但是我認為可以通過在document元素上運行normalise()來解決該問題-我在另一個API上也遇到了類似的問題,並對其進行了修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.