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 に答える