private void organizeNode(Document doc, final String parentName, final String childElName, final String idAttr, final Map<String, Element> addTo) { Element e = doc.getRootElement().element(parentName); if (e != null) { e.accept(new VisitorSupport() { @Override public void visit(Element node) { if (childElName.equals(node.getName())) { String id = node.attributeValue(idAttr); if (id == null) { log.warn("No " + idAttr + " attribute for Node " + node + " in " + name); return; } if (addTo.put(id, node) != null) { log.info("Replaced VFS Entry: " + childElName + "[" + id + "] from " + name); } } } }); } }
/** * Remove comments from XML * * @param document * @throws IOException * @throws DocumentException */ private static void removeComments(Document document) throws IOException, DocumentException { Visitor visitor = new VisitorSupport() { @Override public void visit(Comment comment) { comment.setText(" "); } }; document.accept(visitor); }