On Monday, August 18, 2003, at 07:16 pm, <[EMAIL PROTECTED]> wrote:
Apologies for pestering you with this tedious question, but I've been banging me head for the last few days.
List ps = Dom4jUtils.selectNodes(loadedDoc, "//p"); Element thisP = (Element)ps.get(i); Element pParent = thisP.getParent();
// attempt 1: this removes the target element and appends its replacement
to the end of the doc
pParent.remove(thisP);
pParent.add(tempElement);
// attempt 2: this doesn't work >> ArrayOutOfBoundsException // java.lang.IndexOutOfBoundsException: Index: 2, Size: 0 // pParent.remove(thisP); // pParent.selectNodes("//p").add(i, tempElement);
// attempt 3: document looks exactly like it did before replacement // pParent.selectNodes("//p").remove(i); // pParent.selectNodes("//p").add(i, tempElement);
selectNodes() returns a query list and it is not editable.
If you want to use a List to edit the elements use the elements() method
pParent.elements("p").remove(i); pParent.elements("p") add(i, tempElement);
James ------- http://radio.weblogs.com/0112098/
------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user