|
| |||||||||
| Tags: document, dom, java, node, programming |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| 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. |
|
#2
| ||||
| ||||
| 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); |
|
#3
| |||
| |||
| 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); |
|
#4
| ||||
| ||||
| 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> |
|
#5
| ||||
| ||||
| 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>
|
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |