【发布时间】:2013-02-18 05:41:59
【问题描述】:
我有以下 XML 提要:
<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.
在这里我处理了解析器:
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("\"", """);
noHTMLString = noHTMLString.replaceAll("<(.*?)\\>"," ");//Removes all items in brackets
noHTMLString = noHTMLString.replaceAll("<(.*?)\\\n"," ");//Must be undeneath
noHTMLString = noHTMLString.replaceFirst("(.*?)\\>", " ");
noHTMLString = noHTMLString.replaceAll(" "," ");
noHTMLString = noHTMLString.replaceAll("&"," ");
return noHTMLString;
}
在 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 标记?请为我提供解决方案???
我希望显示没有 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("description value----->"+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("description value----->"+n+att_ID+"------>>"+stringWithoutHTML);}
但我没有得到 o/p..请为我提供解决方案???如何删除这些描述中的 html 标签...
【问题讨论】:
标签: java android html xml-parsing stringbuffer