Parsing html numbers like “½” in dom parser -

2019-06-12 18:10发布

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?

2条回答
你好瞎i
2楼-- · 2019-06-12 18:35

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

查看更多
我只想做你的唯一
3楼-- · 2019-06-12 18:55

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

查看更多
登录 后发表回答