여기에 내 코드XML 문서 (DOM4J)에서 노드를 삭제하는 방법
public Document getNewFeedDocument(Document doc) {
Element root = doc.getRootElement();
List<Node> nodes = doc.selectNodes("Message");
for(int i=0; i<nodes.size(); i++) {
String message_ID = ((Element)nodes.get(i)).selectSingleNode("MessageID").getText();
if(Integer.parseInt(message_ID)%2==0) {
nodes.get(i).detach();
}
}
try {
SAXReader reader = new SAXReader();
return reader.read(new StringReader(root.asXML()));
} catch(Exception e) {
return null;
}
}
이다 그러나 이것은 내가 문서를 수정 얻을 수있는 방법, 같은 문서를 반환합니다.
코드가 노드 목록에서 분리하려고 시도하지만 수정하지 않고 원래 루트로 되돌려 놓습니다. – Vihar