XML processing

zhaozj2021-02-11  205

A simple example to achieve generated XML file with the JDOM package Date: 2003-11-27 Author: ishuo reading people: 297 import java.io *; import org.jdom *; import org.jdom.input *; import org... .jdom.input *;. import org.jdom.output *;. public class test1 {public void BuildXMLDoc () throws IOException, JDOMException {Element eeeRoot, eee1, eee2; Document Doc; eeeRoot = new Element ( "employees_information"); Doc = new document (EEEROOT); Eeeroot = doc.getrootElement (); eee1 = new element ("name"); eee2 = eee1.settext ("cyber"); // eee2 = eee1.addattribute ("EMP_ID", "001"); eee1 = eeeroot.addContent (eee2); eee1 = new element ("age"); eee2 = eee1.Settext ("43"); eee1 = eeeroot.addContent (EEE2); EEE2); EEE1 = New Element (" sex "); eee2 = eee1.setText (" Male "); eee1 = eeeRoot.addContent (eee2); XMLOut.setEncoding (" gb2312 "); XMLOutputter XMLOut = new XMLOutputter (); XMLOut.output (Doc, new FileOutputStream ( "TEST1.XML"));} public static void main (String " ] Args) {TEST1 S1 = new test1 (); system.out.println ("now we build an XML Document ....."); S1.BUILDXMLDOC ();} catch (exception e) {system. Out.println (E.GetMessage ());}}} The output is as follows: - Cy Shen 43 Male

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

New Post(0)