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

问题描述

我在以下XML Feed中有以下内容:

 < Description> 
< p>触摸,点按,翻转,滑动!你不必阅读书籍,而是体验它。< / p>
< / Description>

在这里,我必须显示类似



:触摸,敲击,翻转,滑动!你不要阅读这些书籍,你会体验到它。



这里我处理的解析器如下:

  public static String removeHTML(String htmlString)
{
//从java String中删除HTML标记
String noHTMLString = htmlString.replaceAll( \\<。*?\\>,);

//从java字符串中删除回车符
noHTMLString = noHTMLString.replaceAll(\ r,< br />);
noHTMLString = noHTMLString.replaceAll(<([bip])>。*?< / \1>,);
//从java字符串中删除新行并替换html break
noHTMLString = noHTMLString.replaceAll(\ n,);
noHTMLString = noHTMLString.replaceAll(\,& quot;);
noHTMLString = noHTMLString.replaceAll(<(。*?)\\>, );; //删除括号中的所有项目
noHTMLString = noHTMLString.replaceAll(<(。*?)\\\ n,); //必须在$ b $以下b noHTMLString = noHTMLString.replaceFirst((。*?)\\>,);
noHTMLString = noHTMLString.replaceAll(& nbsp;,);
noHTMLString = noHTMLString.replaceAll(& amp;,);
返回noHTMLString;

}

在endElement中:

  public void endElement(String uri,String localName,String qName)抛出SAXException {
currentElement = false;
if(localName.equalsIgnoreCase(Description)){
sitesList.setDescription(currentValue);
String Sub_arry = n + currentValue ;
Appscontent.Sub_arraylistdes.add(Sub_arry);
String stringWithoutHTML = removeHTML(currentValue);
System.out.pri ntln(描述值----->+ n + att_ID +------>>+ stringWithoutHTML);}

现在我必须运行应用程序意味着html标签与我的描述一起显示...这里如何删除HTML标签?请为我提供解决方案???



我希望显示没有Html标签的说明...请为这些提供解决方案。



编辑:

  if(localName.equalsIgnoreCase(Description) )){
sitesList.setDescription(currentValue);
String Sub_arry = n + currentValue;
StringBuffer sb = new StringBuffer();
sb.append(Sub_arry);
String newString = sb.toString();
Appscontent.Sub_arraylistdes.add(newString);
System.out.println(描述值----->+ n + att_ID +------>>+ newString);}

编辑:

  public static String html2text(String html){
return Jsoup.parse(html).text();
}

在endElement中:

  if(localName.equalsIgnoreCase(Description)){
sitesList.setDescription(currentValue);
String Sub_arry = n + currentValue;
Appscontent.Sub_arraylistdes.add(Sub_arry);
String stringWithoutHTML = html2text(currentValue);
System.out.println(描述值----->+ n + att_ID +------>>+ stringWithoutHTML);}

但我没有得到o / p..pls为我提供这些解决方案???如何删除这些描述中的html标签...

解决方案

您可以使用内置的方式轻松删除Android中的任何HTML标记-in在Android中的HTML类。导入 android.text.Html; 。现在,考虑data是具有HTML标记的String变量,您可以使用 Html.fromHtml(data).toString()来获取不带任何HTML标记的字符串。


I have follows below XML feed:

<Description>
  <p>Touch, tap, flip, slide! You don&#39;t just read Books, you experience it.</p>
</Description>

Here I have to display the description like

Touch,tap,flip,slide! You don 39.just read the Books, you experience it.

Here I have handled the parser like:

   public static String removeHTML(String htmlString)
  {
  // Remove HTML tag from java String
String noHTMLString = htmlString.replaceAll("\\<.*?\\>", "");

// Remove Carriage return from java String
noHTMLString = noHTMLString.replaceAll("\r", "<br/>");
noHTMLString = noHTMLString.replaceAll("<([bip])>.*?</\1>", "");
// Remove New line from java string and replace html break
noHTMLString = noHTMLString.replaceAll("\n", " ");
noHTMLString = noHTMLString.replaceAll("\"", "&quot;");
noHTMLString = noHTMLString.replaceAll("<(.*?)\\>"," ");//Removes all items in brackets
noHTMLString = noHTMLString.replaceAll("<(.*?)\\\n"," ");//Must be undeneath
noHTMLString = noHTMLString.replaceFirst("(.*?)\\>", " ");
noHTMLString = noHTMLString.replaceAll("&nbsp;"," ");
noHTMLString = noHTMLString.replaceAll("&amp;"," ");
return noHTMLString;

    }

In endElement :

   public void endElement(String uri, String localName, String qName)throws SAXException {
  currentElement = false;
   if (localName.equalsIgnoreCase("Description")){
   sitesList.setDescription(currentValue);
   String Sub_arry=n+currentValue;
   Appscontent.Sub_arraylistdes.add(Sub_arry);
   String stringWithoutHTML=removeHTML(currentValue);
   System.out.println("description value----->"+n+att_ID+"------>>"+stringWithoutHTML);}

Now i have to run the app means the html tag is displayed with my description...Here how can I remove the HTML tag? please provide me solution for these ???

i wish to display the description without Html tags...please provide e solution for these.

EDIT:

    if (localName.equalsIgnoreCase("Description")){
    sitesList.setDescription(currentValue);
    String Sub_arry=n+currentValue;
    StringBuffer sb = new StringBuffer();
    sb.append(Sub_arry);
     String newString = sb.toString();
      Appscontent.Sub_arraylistdes.add(newString);
       System.out.println("description value----->"+n+att_ID+"------>>"+newString);}

EDIT:

  public static String html2text(String html) {
  return Jsoup.parse(html).text();
    }

In endElement:

    if (localName.equalsIgnoreCase("Description")){
    sitesList.setDescription(currentValue);
    String Sub_arry=n+currentValue;
    Appscontent.Sub_arraylistdes.add(Sub_arry);
      String stringWithoutHTML=html2text(currentValue);
       System.out.println("description value----->"+n+att_ID+"------>>"+stringWithoutHTML);}

But i didn't get the o/p..pls provide me solution for these ??? how can i remove the html tags in these description...

解决方案

You can easily remove any HTML tag in Android using the built-in HTML class in Android. Import android.text.Html;. Now, considering "data" is your String variable which has HTML tags, you use Html.fromHtml(data).toString() to get back the string without any HTML tags.

这篇关于删除android中的html标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:12