/***** Code de MesExemples.com *******/
/**
* @(#)CreateDomDocument.java
*
*
* @author
*sakoba(java.mesexemples.com) @version 1.00 2013/7/4
*/
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
public class CreateDomDocument {
public static Document newEmptyDocument() {
DocumentBuilderFactory factory = null;
DocumentBuilder builder = null;
Document ret;
try {
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
ret = builder.newDocument();
return ret;
}
}
Code testé avec le fichier XML Suivant
Sakoba
Adams
Rappel
Ne m'oubliez pas ce week-end!