import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import javax.swing.JOptionPane;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
p>public class Test20 { public static void main(String[] args) throws Exception { Document dom=DocumentHelper.createDocument();//Create xml file Element root=dom.addElement("url");// Add the root element, =dom.asXML(); System.out.println(xml); File f=new File("d:/xml.xml"); PrintWriter pw=new PrintWriter(f); pw.write(xml); pw. close(); JOptionPane.showMessageDialog(null, "The xml file has been generated, the path is d:/xml.xml"); }
}
Using dom4j, see Attachment,
Have Fun