/***** Code de MesExemples.com *******/
/**
* @(#)SaveXMLDOM.java
*
*
* @author
*sakoba(java.mesexemples.com) @version 1.00 2013/7/5
*/
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
public class SaveXMLDOM {
public static void main(String[] argv) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder loader = factory.newDocumentBuilder();
Document document = loader.newDocument();
Element order = document.createElement("note");
document.appendChild(order);
XMLSerializer serializer = new XMLSerializer();
serializer.setOutputCharStream(new java.io.FileWriter("note.xml"));
serializer.serialize(document);
}
}
Code testé avec le fichier XML Suivant
Sakoba
Adams
Rappel
Ne m'oubliez pas ce week-end!