Element parent = new Element("parent"); Element child = new Element("child"); parent.addContent("This is my child node"); parent.addContent(child);
Element root = new Element("root"); Element child = new Element("child"); child.setAttribute("foo", "bar"); root.addContent(child);In this example, a new element "root" is created, then a child element "child" is created and an attribute "foo" is added to it having value "bar". Then the child element is added to the root element using the addContent method. Package Library: org.jdom