dom4j InsertElement

E

Emmanuel

I am trying to use the method from the dom4j Library to insert new
element it to an existing xml but I keep getting an error. Is any one
familiar with the dom4j Library? I need help. I am new to Dom4j.
Inserting elements sometimes it's necessary to insert an element in a
existing XML Tree. This is easy to do using dom4j Collection API.
Need help thanks

public void insertElementAt(Element newElement, int index) {
Element parent = this.element.getParent();
List list = parent.content();
list.add(index, newElement);
}

public void testInsertElementAt() {

//insert an clone of current element after the current element
Element newElement = this.element.clone();
this.insertElementAt(newElement,
this.root.indexOf(this.element)+1);

// insert an clone of current element before the current element
this.insertElementAt(newElement,
this.root.indexOf(this.element));
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top