简体   繁体   English

html字符串到java字符串的转换,删除html,css等标签

[英]conversion of html string into java string removing html, css etc tags

I am working on a project where data is coming from a server. 我正在一个项目中,数据来自服务器。 In certain fields data is stored in html format. 在某些字段中,数据以html格式存储。 My problem is that i want to display that information in Android Text View. 我的问题是我想在Android文本视图中显示该信息。 but not with this html part. 但与此HTML部分无关。 However, I want to keep the Line break information intact So, that it can properly displayed to user. 但是,我想保持换行信息完整,以便可以正确显示给用户。 I have tried Jsoup.clean but it also left some style sheet data, like , 我尝试了Jsoup.clean,但它还留下了一些样式表数据,例如,

  • elements etc One of sample string is : 元素等示例字符串之一是:

     <ul style="list-style-position: initial; list-style-image: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 14px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; margin: 0px;"> <li style="line-height: 18px; padding: 0px; margin: 0px;">Offer is on a choice of veg or non-veg meals for Two <ul style="list-style-type: disc; list-style-position: initial; list-style-image: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 14px; line-height: normal; margin: 0px;"> <li style="line-height: 18px; padding: 0px; margin: 0px;"><strong>Offer 1- Rs.499 Worth Rs. 1000:</strong> Veg Lunch OR Dinner for 2 Persons</li> <li style="line-height: 18px; padding: 0px; margin: 0px;"><strong>Offer 2 – Rs.599 Worth Rs. 1200:</strong> Non-Veg Lunch OR Dinner for 2 Persons</li> </ul> </li> <li style="line-height: 18px; padding: 0px; margin: 0px;">Traditional restaurant serving authentic cuisine in mud pots</li> <li style="line-height: 18px; padding: 0px; margin: 0px;">Inclusive of all taxes and service charges</li> <li style="line-height: 18px; padding: 0px; margin: 0px;"><strong><span class="upc gry sml">Cost for 2: </span>Rs. 700</strong></li> </ul> 

    after applying jsoup.clean the string becomes 应用jsoup.clean之后,字符串变为

      <ul style="list-style-position: initial; list-style-image: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 14px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; margin: 0px;"> <li style="line-height: 18px; padding: 0px; margin: 0px;">Offer is on a choice of veg or non-veg meals for Two <ul style="list-style-type: disc; list-style-position: initial; list-style-image: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 14px; line-height: normal; margin: 0px;"> <li style="line-height: 18px; padding: 0px; margin: 0px;"><strong>Offer 1- Rs.499 Worth Rs. 1000:</strong>&nbsp;Veg Lunch OR Dinner for 2 Persons</li> <li style="line-height: 18px; padding: 0px; margin: 0px;"><strong>Offer 2 &ndash; Rs.599 Worth Rs. 1200:</strong>&nbsp;Non-Veg Lunch OR Dinner for 2 Persons</li> </ul> </li> <li style="line-height: 18px; padding: 0px; margin: 0px;">Traditional restaurant serving authentic cuisine in mud pots</li> <li style="line-height: 18px; padding: 0px; margin: 0px;">Inclusive of all taxes and service charges</li> <li style="line-height: 18px; padding: 0px; margin: 0px;"><strong><span class="upc gry sml">Cost for 2: </span>Rs. 700</strong></li> </ul> 

    Please help me solving this issue. 请帮助我解决这个问题。

  • 尝试这个

    html.fromHtml(string);

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM