Parsing html numbers like “&#189” in dom parser - android

隐身守侯 提交于 2019-12-23 05:12:23

问题


I am developing an android project. I am using dom parser to parse the xml file. Issue is my xml file contains html numbers like &#189 (semicolon will come in the end of every char code)

for example

<quote>We &#8220;love&#8221; our nation</quote> 

which is nothing but

<quot>We "love" our nation</quote> 

I am not able to parse this html number in dom parse, when I try to get the node value, I am getting null.

Can anyone tel me how to parse this html character codes?

or

How to convert this html char code as either text char code or unicode char set in my xml feed?


回答1:


There is a very similar question here: Android decoding html in xml file

It seems the html characters break the DOM parser, so it is unable to get the string from the xml entity.

There is a HTML function to parse HTML in a string:

TextView tv = (TextView) findViewById(R.id.tv);
String s = <quote>We &#8220;love&#8221; our nation</quote>";
tv.setText(Html.fromHtml(s));

Outputs:

We "love" our nation

However it seems the DOM isn't getting the string to convert, so the following article maybe useful: Using XPATH and HTML Cleaner to parse HTML / XML




回答2:


I have used xmlpullparser. Its working fine now. :)



来源:https://stackoverflow.com/questions/4132092/parsing-html-numbers-like-189-in-dom-parser-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!