Element root = new Element("root"); Element child1 = new Element("child1"); Element child2 = new Element("child2"); root.addContent(child1); root.addContent(child2); Element firstChild = root.getChild("child1"); System.out.println(firstChild.getName()); // Output: child1
Element root = new Element("root"); Element child1 = new Element("child1"); child1.setAttribute("attr", "value"); root.addContent(child1); Element firstChildAttr = root.getChild("child1").getAttribute("attr"); System.out.println(firstChildAttr.getValue()); // Output: valueIn this example, we create an Element called "root" and add a child element called "child1" with an attribute called "attr" and value "value". We then retrieve the first child element using the getChild() method and access its attribute value using the getAttribute() method. These examples use the org.jdom package library.