あなたはこのようなことを試すかもしれません
String str = "<title>Episode #56 – Heroes</title>";
str = str.replaceAll("&", "amp;");
次に、「str」を解析してみてください。動作するはずです。
これは、dom パーサーを使用した純粋な実装のサンプルです。
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());
}