,你可以嘗試一些這樣的事
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