I am trying to replace/exchange attributes from a new element to an existing element.

newElem looks like:

<page id="abc" label="boo" name="boo.html" generate="1" xmlns="myns"></page>
(The namespace matches the namespace of the existing element. I have also tried without the namespace)



The method below breaks with an IndexOutOfBoundsException exception (further below). The length int's value is println'd out as 4.


Any ideas what I am doing wrong?

thanks,
-Rob


public final Element updateElement(Element context, Element newElem) throws UnavailableException {
Element focusElem = elementByID(context, newElem.attributeValue("id"));


 focusElem.attributes().clear();

 List attrs = newElem.attributes();
 int length = attrs.size();
System.out.println("updateElement length: " + length);

 for (int i=0; i < length; i++) {
   Attribute attr = (Attribute) attrs.get(i);
System.out.println("updateElement attr: " + attr);
   focusElem.add(attr.detach());
 }

 return focusElem;
}

java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.get(ArrayList.java:324)
at org.dom4j.tree.ContentListFacade.get(ContentListFacade.java:130)
at com.livestoryboard.actions.LsbFilter.updateElement(Unknown Source)
at com.livestoryboard.actions.architecture.SaveFilter.doFilter(Unknown Source)
....snip




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to