Why not Node.insertAfter()?

Hi,
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
the
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");
 element.appendChild(document.createTextNode(number));
 parent.insertAfter(element, lastPhone);
 lastPhone = element;
}
What I end up doing is remembering what the firstNode of computer is and
do
an insertBefore. This seems kind of wierd that I need to know the next
unrelated
element and do an insertBefore.
Am I missing something?
Does DOM 2 change this?
Thanks,
Eric :-)

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

AltStyle によって変換されたページ (->オリジナル) /