Solved

Adding elements to a dom tree

Posted on 2004-04-28
7
302 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now