Spécial HTML character ( & # 39; -> quot ) in XML file

醉酒当歌 提交于 2019-12-24 22:47:43

问题


I got an " & # 39; " in my XML file. (it is the char code for the quot in HTML)

EX :

< desc > blabla bla & # 39; bla bla la. < / desc>

When i parse it with String tmp = itemOfEvent.getFirstChild().getNodeValue() it cut my text juste before the quot.

I got a crash with URL.encode(tmp, "UTF-8")

Better idea ?


回答1:


You say that the text is HTML encoded so try this:

String fixedTmp = Html.fromHtml(tmp).toString();



回答2:


The best solution i've found was to replace bad char

xmlString = xmlString.replaceAll(" & #39;", " \ ' ");



回答3:


I assume you're parsing the XML file with a SAXParser? In this case, note that the 'characters()'-method can be called multiple times while parsing a single Element (as it does in your case). Try this:

private StringBuilder temp_val;
public void characters(char[] ch, int start, int length){
    temp_val.append(ch, start, length);
}


来源:https://stackoverflow.com/questions/5948654/sp%c3%a9cial-html-character-39-quot-in-xml-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!