Element root = new Element("root"); // create the root element Element child1 = new Element("child1"); // create a child element Element child2 = new Element("child2"); // create another child element root.addContent(child1); // add the child1 element to the root element root.addContent(child2); // add the child2 element to the root element
Element element = new Element("parent"); // create a parent element Element child = new Element("child"); // create a child element child.setText("This is the content for the child element"); // set the text for the child element element.addContent(child); // add the child element to the parent element
import org.jdom2.Element;This statement imports the Element class from the JDOM package.