問題描述
我有以下 XML 提要:
I have follows below XML feed:
<Description>
<p>Touch, tap, flip, slide! You don't just read Books, you experience it.</p>
</Description>
這里我必須顯示類似
觸摸、點擊、翻轉、滑動!你不 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("
", "<br/>");
noHTMLString = noHTMLString.replaceAll("<([bip])>.*?</1>", "");
// Remove New line from java string and replace html break
noHTMLString = noHTMLString.replaceAll("
", " ");
noHTMLString = noHTMLString.replaceAll(""", """);
noHTMLString = noHTMLString.replaceAll("<(.*?)\>"," ");//Removes all items in brackets
noHTMLString = noHTMLString.replaceAll("<(.*?)\
"," ");//Must be undeneath
noHTMLString = noHTMLString.replaceFirst("(.*?)\>", " ");
noHTMLString = noHTMLString.replaceAll(" "," ");
noHTMLString = noHTMLString.replaceAll("&"," ");
return noHTMLString;
}
在 endElement 中:
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);}
現在我必須運行該應用程序,這意味著 html 標記與我的描述一起顯示...在這里如何刪除 HTML 標記?請為我提供解決方案???
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 ???
我希望顯示沒有 Html 標記的描述...請為這些提供解決方案.
i wish to display the description without Html tags...please provide e solution for these.
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);}
public static String html2text(String html) {
return Jsoup.parse(html).text();
}
在 endElement:
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);}
但我沒有得到 o/p..請為我提供解決方案???如何刪除這些描述中的 html 標簽...
But i didn't get the o/p..pls provide me solution for these ??? how can i remove the html tags in these description...
推薦答案
您可以使用 Android 中內置的 HTML 類輕松刪除 Android 中的任何 HTML 標簽.導入 android.text.Html;
.現在,考慮到數據"是具有 HTML 標記的字符串變量,您可以使用 Html.fromHtml(data).toString()
來取回沒有任何 HTML 標記的字符串.
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標簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!