开发者

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

开发者 https://www.devze.com 2023-01-24 07:28 出处:网络
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)

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.

开发者_C百科

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?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号