Solved

Adding elements to a dom tree

Posted on 2004-04-28
7
308 Views
Last Modified: 2013-11-24
I'm adding elements to a dom tree and i can add to the head of a node using the code:

Element firstElement = (Element) nl.item(1);
firstElement.getParentNode ().insertBefore (newNode, firstElement);

This will add the element <init-param> to the start of the servlet as follows:
<servlet>
  <init-param>
   <param-name>param1</param-name>
   <param-value>param1</param-value>
  </init-param>
  <servlet-name>servletA</servlet-name>
  <servlet-class>servlets.servletA</servlet-class>
</servlet>

This is wrong though how can i add it so that it will be the last in servlet like:

<servlet>
  <servlet-name>servletA</servlet-name>
  <servlet-class>servlets.servletA</servlet-class>
  <init-param>
   <param-name>param1</param-name>
   <param-value>param1</param-value>
  </init-param>
</servlet>
0
Comment
Question by:liamgannon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10943653
How about

servletRoot.appendChild

?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 10943657
Or in your code case

firstElement.getParentNode().appendChild
0
 

Author Comment

by:liamgannon
ID: 10943692
will i then be the last element of <servlet>?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 86

Expert Comment

by:CEHJ
ID: 10943704
Should be yes
0
 
LVL 92

Expert Comment

by:objects
ID: 10943985
0
 

Author Comment

by:liamgannon
ID: 10944280
Cheers CEHJ ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10944440
:-)
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question