Any ideas how we do this apart from the long-winded use of
someElement.elements()?

Thanks,
Portia



|---------+-------------------------------------->
|         |           James Strachan             |
|         |           <[EMAIL PROTECTED]|
|         |           >                          |
|         |           Sent by:                   |
|         |           [EMAIL PROTECTED]|
|         |           ceforge.net                |
|         |                                      |
|         |                                      |
|         |           19/08/2003 06:03           |
|         |                                      |
|---------+-------------------------------------->
  
>-------------------------------------------------------------------------------------------------------|
  |                                                                                    
                   |
  |       To:       <[EMAIL PROTECTED]>                                                
                    |
  |       cc:       [EMAIL PROTECTED]                                                  
    |
  |       Subject:  [dom4j-user] Re: Replacing an element in a document                
                   |
  
>-------------------------------------------------------------------------------------------------------|





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










**********************************************************************************
This email may contain confidential material. If you were not an
intended recipient, please notify the sender and delete all copies.
We may monitor email to and from our network.



-------------------------------------------------------
This SF.net email is sponsored by Dice.com.
Did you know that Dice has over 25,000 tech jobs available today? From
careers in IT to Engineering to Tech Sales, Dice has tech jobs from the
best hiring companies. http://www.dice.com/index.epl?rel_code=104
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to