XmlDocument appendChild method
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Becky_Givner
Posted On:   Wednesday, September 26, 2001 11:21 AM

Is it possible to append a given element to multiple nodes in an XmlDocument? For example: import com.sun.xml.tree.XmlDocument; import org.w3c.dom.Element; ... XmlDocument doc = new XmlDocumentBuilder().createDocument(); Element root = doc.createElement("root"); Element parent1 = doc.createElement("parent1"); Element parent2 = doc.createElement("parent2"); Element parent3 = doc.createElement("parent3"); doc.createElement("child1"); parent1.appendChild(child1); parent2.appendChild(child1); parent3.appendChild(child1); root.appendChild(p   More>>

Is it possible to append a given element to multiple nodes in an XmlDocument?


For example:


			


import com.sun.xml.tree.XmlDocument;
import org.w3c.dom.Element;

...

XmlDocument doc = new XmlDocumentBuilder().createDocument();

Element root = doc.createElement("root");

Element parent1 = doc.createElement("parent1");
Element parent2 = doc.createElement("parent2");
Element parent3 = doc.createElement("parent3");

doc.createElement("child1");

parent1.appendChild(child1);
parent2.appendChild(child1);
parent3.appendChild(child1);

root.appendChild(parent1);
root.appendChild(parent2);
root.appendChild(parent3);

doc.appendChild(root);




The result I get is that child1 is appended to parent3 only.


What is the reason for this?

   <<Less
About | Sitemap | Contact