Hi all, When I use dom4j to create xml source, I met some problems.
Here is my code, I want to create xml source from Document object. ----------------------------------------------------- public static void main(String[] args) { Document document = DocumentHelper.createDocument(); Element element1 = document.addElement("tag1"); element1.addAttribute("name","test"); element1.addNamespace("","http://aaa.bbb"); Element element2 = element1.addElement("tag2"); OutputFormat format = OutputFormat.createPrettyPrint(); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); String formatted = ""; try { writer.write(document); formatted = stringWriter.toString(); writer.close(); } catch (IOException ex) { ex.printStackTrace(); } System.out.println(formatted); } ------------------------------------------------------ Here is my output result: ------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <tag1 xmlns="http://aaa.bbb" name="test"> <tag2 xmlns=""/> </tag1> ------------------------------------ I found tag2 element always has a attribute which named "xmlns". I want to let the tag2 element has no attribute. And "<?xml version="1.0" encoding="UTF-8"?>" always show in the head of xml source. Has any way to avoid the "<?xml version="1.0" encoding="UTF-8"?>" show in the xml source? What should I do? Has any wrong in my code? THX. ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click _______________________________________________ dom4j-user mailing list dom4j-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-user