당신은 'STR'구문 분석하려고이
String str = "<title>Episode #56 – Heroes</title>";
str = str.replaceAll("&", "amp;");
같은 몇 가지 일을하려고 할 수 있습니다 그것은 작동합니다.
여기에 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());
}
이 시도했지만 작동하지 않았다 : String title = parser.getValue (e, KEY_TITLE); myObj.setTitle (title.replaceAll ("&", "amp;")); // 같은 문제. –
@Rafael 그것은 작동합니다. 주어진 샘플 코드가 있지만, Dalvic 런타임으로 테스트하지는 않았지만 로직을 올바르게 구현할 수 있습니까? – Sark