就是生成一個xml,照著例子做就是了
使用List生成一個Document,Document你可以隨便處理,甚至於儲存到XML中,或者傳給其他物件
Javacode
importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importjava.util.ArrayList;importjava.util.List;importjavax.xml.parsers.DocumentBuilder;importjavax.xml.parsers.DocumentBuilderFactory;importjavax.xml.parsers.ParserConfigurationException;importjavax.xml.transform.Transformer;importjavax.xml.transform.TransformerConfigurationException;importjavax.xml.transform.TransformerException;importjavax.xml.transform.TransformerFactory;importjavax.xml.transform.dom.DOMSource;importjavax.xml.transform.stream.StreamResult;importorg.w3c.dom.Document;importorg.w3c.dom.Element;importorg.xml.sax.SAXException;publicclassTest{publicstaticvoidmain(String[]args)throwsParserConfigurationException,SAXException,IOException{DocumentBuilderFactoryfactory=DocumentBuilderFactory.newInstance();factory.setIgnoringElementContentWhitespace(true);DocumentBuilderdb=factory.newDocumentBuilder();//Documentdoc=db.parse(newFile("user.xml"));Documentdoc=db.newDocument();//Elementroot=doc.create;List
輸出
XMLcode
就是生成一個xml,照著例子做就是了
使用List生成一個Document,Document你可以隨便處理,甚至於儲存到XML中,或者傳給其他物件
Javacode
importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importjava.util.ArrayList;importjava.util.List;importjavax.xml.parsers.DocumentBuilder;importjavax.xml.parsers.DocumentBuilderFactory;importjavax.xml.parsers.ParserConfigurationException;importjavax.xml.transform.Transformer;importjavax.xml.transform.TransformerConfigurationException;importjavax.xml.transform.TransformerException;importjavax.xml.transform.TransformerFactory;importjavax.xml.transform.dom.DOMSource;importjavax.xml.transform.stream.StreamResult;importorg.w3c.dom.Document;importorg.w3c.dom.Element;importorg.xml.sax.SAXException;publicclassTest{publicstaticvoidmain(String[]args)throwsParserConfigurationException,SAXException,IOException{DocumentBuilderFactoryfactory=DocumentBuilderFactory.newInstance();factory.setIgnoringElementContentWhitespace(true);DocumentBuilderdb=factory.newDocumentBuilder();//Documentdoc=db.parse(newFile("user.xml"));Documentdoc=db.newDocument();//Elementroot=doc.create;List
輸出
XMLcode