import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; import org.jdom.JDOMException; import org.jdom.Element; import org.jdom.EntityRef; import org.jdom.Attribute; import org.jdom.Namespace; import org.jdom.*; import java.io.*; import java.io.IOException; import java.util.ListIterator; import java.util.List; import java.io.*; class HPNEWXML { public void dohpxml() { Namespace ns = Namespace.getNamespace("PREF","Namespace"); Namespace ns1 = Namespace.getNamespace("Namespace2"); Element root = new Element("Root"); Document document = new Document(root); Element e1 = new Element("E1"); e1.addContent("E1 Content"); Element e2 = new Element("E2"); e2.addContent("E2 Content"); Element e3 = new Element("E3"); e1.addContent(e2); Attribute a1 = new Attribute("A1attr", "a1attr value"); Attribute a2 = new Attribute("A2attr", "a2attr value"); Attribute atemp = (Attribute) a2.clone(); //a2.setNamespace(ns); root.setNamespace(ns1); //e1.setNamespace(ns); e1.setAttribute(a1); e2.setAttribute(a2); e1.setAttribute(atemp); root.addContent(e1); root.addContent(e3); XMLOutputter xmloutputter = new XMLOutputter(" ", true); try { xmloutputter.output(document, System.out); } catch(IOException e) { System.out.println("IOException = ["+e.getMessage()+"]"); } } public static void main(String[] args) { HPNEWXML hpnewxml = new HPNEWXML(); hpnewxml.dohpxml(); } }