Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Adding a Node to a DOM Document

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 02-03-2010
Level8's Avatar
Member
 
Join Date: Nov 2009
Posts: 873
Adding a Node to a DOM Document

Hello, I am learning java programming language and while working on in, I want to know the details about the Adding a Node to a DOM Document. I have search this on internet and unable to get the details about it, If you are having knowledge about it, then provide some details which will be helpful to me for getting solution for this problem. Thank you in advance.
Reply With Quote
  #2  
Old 02-03-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
Re: Adding a Node to a DOM Document

Hello, If you want to create a node to a DOM Document, then you must need to use the code below and add it to your program:
Code:
Document document = createDomDocument(); 
Element ele = document.createElement("root"); 
document.appendChild(ele); 
Domment cmnt = document.createDomment("Comment"); 
document.insertBefore(cmnt, ele); 
ele.appendChild(document.createTextNode("First")); 
ele.insertBefore(document.createTextNode("Second"), ele.getFirstChild()); 
ele.insertBefore(document.createTextNode("Third"), ele.getLastChild()); 
Element ele2 = document.createElement("item"); 
ele.insertBefore(ele2, ele.getFirstChild().getNextSibling()); 
ele2.getParentNode().insertBefore(document.createTextNode("B"), ele2);
Reply With Quote
  #3  
Old 02-03-2010
Member
 
Join Date: May 2008
Posts: 1,990
Re: Adding a Node to a DOM Document

If you consider the source code below then you will come to know that the method appendChild() is used for the addign a node to a DOM document. So, just make use of it.
Code:
xmlDoc=loadXMLDoc("Techarena.xml");

newelement=xmlDoc.createElement("Website");

test=xmlDoc.getElementsByTagName("Techarena")[0];
test.appendChild(newelement);
Reply With Quote
  #4  
Old 02-03-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
Re: Adding a Node to a DOM Document

Hello, if you want to Access a node using its index number from the node list then you can make use of the code below and get your problem solved:
Code:
<html>
<head>
<script type="text/javascript" src="loadingdoc.js"></script>
</head>
<body>
<script type="text/javascript">
Doc=loadXMLDoc("Testing.xml");
x=Doc.getElementsByTagName("NodeTesting");
document.write(x[2].childNodes[0].nodeValue);
</script>
</body>
</html>
Reply With Quote
  #5  
Old 02-03-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
Re: Adding a Node to a DOM Document

Hey, I have got the javascript below which will simply append the Node to the Document and provide you solution for your problem.
Code:
<script type="text/javascript">
function Adding(what){
if (doc.createTextNode){
var mytext=doc.createTextNode(what)
doc.getElementById("mydiv").appendChild(mytext)
}
}
</script>
<div id="mydiv" onClick="Adding(' Text will be added')" style="font:25px bold; cursor:hand">Test It</div>
Here, you must need to know the some of the details of the terms below:
  • Node: It is a reference for the element or attribute or text.
  • Element: Element is a presentation of a <TAG>.
  • Attribute: A element posses some of the property which is termed as a Attribute.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Adding a Node to a DOM Document"
Thread Thread Starter Forum Replies Last Post
Adding Microsoft Office Document Image Writer Printer back after being removed. ex MS Office Support 3 22-09-2011 06:38 AM
Access denied when adding a second node Pascal MIETLICKI Windows Server Help 5 12-05-2010 01:20 PM
Adding Office Document Imaging and OCR to Home and Student 2007 HorseDoc MS Office Support 9 20-01-2008 11:00 PM
clustering 2003 adding a node Danno Windows Server Help 16 04-03-2006 12:20 AM
Adding 2nd node fails James Evans Windows Server Help 4 31-10-2005 09:07 PM


All times are GMT +5.5. The time now is 05:23 AM.