dom4j InsertElement

Discussion in 'XML' started by Emmanuel, Oct 23, 2006.

  1. Emmanuel

    Emmanuel Guest

    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));
    }
    Emmanuel, Oct 23, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wolfgang
    Replies:
    0
    Views:
    620
    Wolfgang
    Jul 9, 2003
  2. Stefan Siegl
    Replies:
    2
    Views:
    729
    David Zimmerman
    Jul 17, 2003
  3. Cram TeXeD
    Replies:
    1
    Views:
    349
    Cram TeXeD
    Feb 2, 2004
  4. Timo Nentwig
    Replies:
    0
    Views:
    858
    Timo Nentwig
    Feb 4, 2004
  5. Emmanuel

    InsertElement dom4j Q

    Emmanuel, Oct 23, 2006, in forum: Java
    Replies:
    3
    Views:
    1,150
    Emmanuel
    Nov 2, 2006
Loading...

Share This Page