在j2me中处理文本html [英] handle text html in j2me

查看:179
本文介绍了在j2me中处理文本html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作应用程序的RSS新闻,它可以给用户提供详细的新闻。



当我进入细节时,正文文本显示html标记。



这是我的照片申请:



我没有想要显示html标签。



这是我的代码,显示详细信息页面:

  private void detailScreen(News news){
Form form = new Form(news.getTitle());

StringItem detail = new StringItem(,news.getBody()。toString());
mBackCommand = new Command(Back,Command.BACK,0);

form.append(detail);
form.addCommand(mBackCommand);
form.setCommandListener(this);

// Canvas c = new MyCanvas(this,news);

mDisplay.setCurrent(form);
}

请有人告诉我我在这里做错了什么?

解决方案

使用 jsoup

使用它:

  Jsoup.parse(htmlText ).text()

如果你有这个库,你的代码现在可以写成:

  private void detailScreen(News news){
Form form = new Form(news.getTitle());

StringItem detail = new StringItem(,Jsoup.parse(news.getBody()。toString())。text());
mBackCommand = new Command(Back,Command.BACK,0);

form.append(detail);
form.addCommand(mBackCommand);
form.setCommandListener(this);

// Canvas c = new MyCanvas(this,news);

mDisplay.setCurrent(form);
}




更新


其他解析器选项:

http://jericho.htmlparser.net/docs/index.html
http://jericho.htmlparser.net/docs/javadoc/net/htmlparser/jericho/TextExtractor.html



但即使在这种情况下,完整的库可能无法编译,您可能需要提取所需的类。这在使用j2me时总是如此。



这也许是有用的:

http://www.j2mehtml.com/j2mehtml/index.htm


I tried to make application RSS news, and it can give detail news to user.

When I go to detail, the body text is show the html tag.

This is picture of my application:

I don't want to show html tags.

This is my code to show detail page:

private void detailScreen(News news){
    Form form = new Form(news.getTitle());

    StringItem detail = new StringItem("", news.getBody().toString());
    mBackCommand = new Command("Back", Command.BACK, 0);

    form.append(detail);
    form.addCommand(mBackCommand);
    form.setCommandListener(this);

    //Canvas c = new MyCanvas(this, news);

    mDisplay.setCurrent(form);
}

Please can someone tell me what's I'm doing wrong here?

解决方案

Its quite simple to do with jsoup

using it:

Jsoup.parse(htmlText).text()

if you have that library your code can now be written as:

private void detailScreen(News news){
    Form form = new Form(news.getTitle());

    StringItem detail = new StringItem("",Jsoup.parse(news.getBody().toString()).text());
    mBackCommand = new Command("Back", Command.BACK, 0);

    form.append(detail);
    form.addCommand(mBackCommand);
    form.setCommandListener(this);

    //Canvas c = new MyCanvas(this, news);

    mDisplay.setCurrent(form);
}

UPDATE

Other parser options:

http://jericho.htmlparser.net/docs/index.html http://jericho.htmlparser.net/docs/javadoc/net/htmlparser/jericho/TextExtractor.html

But even in this case complete library may not compile and you may have to extract the classes you need. This is always the case when working with j2me.

Also this might be useful:

http://www.j2mehtml.com/j2mehtml/index.htm

这篇关于在j2me中处理文本html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆