Pierrick Brihaye wrote: > > >>OK, I can write it myself but I lack some examples for traversing the > >>document's tree. > > > > See > > http://www.xmlmind.com/xmleditor/_distrib/docs/dev/ar01s04.html#d0e1243. > > No example here :-(
Sorry. The example is here: http://www.xmlmind.com/xmleditor/_distrib/docs/dev/ar01s04.html#dom.node -------------------------------------------------------------- private static void add(Element parent, Element added) { Name addedName = added.getName(); String addedClass = added.getAttribute(CLASS); boolean replaced = false; loop: for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { switch (child.getNodeType()) { case Node.TEXT: case Node.COMMENT: case Node.PROCESSING_INSTRUCTION: break; case Node.ELEMENT: { Element element = (Element) child; if (element.getName() == addedName && addedClass.equals(element.getAttribute(CLASS))) { parent.replaceChild(element, added); replaced = true; break loop; } } break; } } if (!replaced) parent.insertChild(parent.getFirstChild(), added); } -----------------------------------------------------------

