----- Original Message ----- From: "Silvain Piree" <[EMAIL PROTECTED]> > Bob, > > > Element parent = element.getParent(); > > List children = parent.elements(); > > int elemLoc = children.indexOf( element ); > > Element nextSibling = children.get( elemLoc + 1 ); > > Element prevSibling = children.get( elemLoc - 1 ); > > This won't work either, because indexOf() uses the node list (including > attribute nodes, etc.) whereas elements() returns a list containing only > elements (so index for node list can be used for list containing only > elements).
Not quite - the indexOf() operates on the list in question, whether its a filtered selection or the whole content node list. So this could be the list of all content nodes or the list of just the elements, or even a list of all elements with a certain name or QName. So the same technique can be used to find the next & previous node, element or even element with a given local or QName. e.g. both ways work. e.g. Element parent = element.getParent(); // get next & previous nodes List nodes = element.content(); int nodeLoc = nodes.indexOf( element ); Node nextNode = (Node) nodes.get( nodeLoc + 1 ); Node prevNode = (Node) nodes.get( nodeLoc - 1 ); // get next & previous elements List elements = parent.elements(); int elemLoc = elements.indexOf( element ); Element nextSibling = (Element) elements.get( elemLoc + 1 ); Element prevSibling = (Element) elements.get( elemLoc - 1 ); // you could even create a List of all the <foo/> elements. List foos = parent.elements( "foo" ); int elemLoc = foos.indexOf( element ); Element nextFoo= (Element) foos.get( elemLoc + 1 ); Element prevFoo = (Element) foos.get( elemLoc - 1 ); James _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user
