Good tool for XML file processing - generating XML document --CNJsp.org

xiaoxiao2021-03-06  82

http://www.cnjbb.org/thread.jsp?boardid=46&threadid=43597&pageno=1&perpage=10&mode=block here will make you more quickly learn Java! Not only give a good tutorial, but also have Java cattle to give you Develop plans and answer questions! Cnjsp.org is very good! This article continues to introduce JDOM to generate XML files: (1) First generation of Document objects first, write in the file with the following code (such as file in c: /car.xml): public void WriteTofile (Document doc, String filePath) {try {org.jdom.output.XMLOutputter outputter = new org.jdom.output.XMLOutputter (); outputter.output (doc, System.out); FileWriter writer = new FileWriter (filePath); // Filepath = c: /car.xml outputter.Output (doc, writer); Writer.close ();} catch (java.io iexcection) {E.PrintStackTrace ();}} (2) A simpler XML Document object: Toyota Celica 1997 Green 1abc234 Create a Document: Element car = new element ("car"); Document Doc = New Document (car); add Element in this! Add an attribute: car.addattribute (New Attribute ("VIN", "VIN"); Element Make = New Element ("Make"); Make.AddContent ("Toyota"); car.addcontent (Make ); Add the rest of the element: car.addContent (New Element ("modica"); car.addcontent (New Element ("Year"). AddContent ("1997"); car.addContent (New Element). AddContent ("Green")); car.addcontent (New Element ("license"). AddContent ("1Abc234"). Addttribute ("State", "CA"); JDOM is Not very simple! ! !

转载请注明原文地址:https://www.9cbs.com/read-95150.html

New Post(0)