I am using the google books api for an Android app that I am building. This is a sample of the XML file
<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>
And this is a fraction of the code I'm using to extract the description
if ( entry.getElementsByTagName( "dc:description" ).item( 0 ) != null ) {
Element d = ( Element ) entry.getElementsByTagName( "dc:description" )
.item( 0 );
b.setDescription( d.getFirstChild( ).getNodeValue( ) );
}
The problem is when using the HTML.fromHtml(Str) function it cuts off the text at the first HTML entity (so in this example it says simply
This trilogy includes
When I run the same code outside of Android it works ok and at least shows the string with the escape characters, i.e.
This trilogy includes " The Hitchhiker's Guide to the Galaxy" , " TheRestaurant at the End of the Universe" , " Life, Universe and Everything" and " So Long ...
If I then manually add this to the app the HTML.fromHtml() works fine so I guess the problem is Android's implementation of the parser.
A similar pr开发者_运维百科oblem is Android decoding html in xml file. I have tried setting the validation of the factory to false, and as it is an RSS feed I cannot declare an HTML root element (as suggested in this post).
I ended up not getting the description data from Google but I think the problem might be solved by running normalise() on the document element - I had a similar problem with another API and that fixed it.
精彩评论