,你可以尝试一些这样的事
String str = "<title>Episode #56 – Heroes</title>";
str = str.replaceAll("&", "amp;");
然后尝试解析“STR”它应该工作。
这里是pure with dom parser的示例实现。
public static void main(String[] args) throws XPathExpressionException {
String str = "<title>Episode #56 – Heroes</title>";
str = str.replaceAll("&", "amp;");
Document domDoc = null;
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());
domDoc = docBuilder.parse(bis);
} catch (Exception e) {
e.printStackTrace();
}
NodeList nlist = domDoc.getElementsByTagName("title");
//System.out.println("child count "+nlist.getLength());
System.out.println("title value = "+nlist.item(0).getTextContent());
}
我试过了,但没有工作:String title = parser.getValue(e,KEY_TITLE); myObj.setTitle(title.replaceAll(“&”,“amp;”)); // 同样的问题。 –
@Rafael它的工作我有一个给定的示例代码,但它没有用dalvic运行时进行测试,但逻辑可以实现对吗? – Sark