W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2000

Why not Node.insertAfter()?

From: Eric Richardson <maxwell@telesoft.com>
Date: Wed, 08 Mar 2000 09:27:18 -0700
Message-ID: <38C67F65.E04E4856@telesoft.com>
To: DOM <www-dom@w3.org>
I'm working with Dom level 1, xmltr2 package from sun. The following is
a simple example
of what I am doing but using the insertBefore() method.

<!ELEMENT person (phone*, computer*)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT computer (#PCDATA)>

I'm creating a class that allows the client to add phones and computers
to this
hypothetical person document. I want to add new phones and computers
as new Nodes after the last one in the group. If I keep a reference to
last one in the group (phones or computers) then it seems that it would
be easiest and most context
free to do the following.

class Person {
    Document document;
    Element lastPhone;
    Element lastComputer;

void addPhone(String number) {
     // assume last phone not null
    Node parent = lastPhone.getParentNode();
    Element element = document.createElement("phone");
     parent.insertAfter(element, lastPhone);
    lastPhone = element;

What I end up doing is remembering what the firstNode of computer is and
an insertBefore. This seems kind of wierd that I need to know the next
element and do an insertBefore.

Am I missing something?
Does DOM 2 change this?

Eric :-)
Received on Wednesday, 8 March 2000 11:29:23 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:06 UTC