Java tutorial
//package com.java2s; import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main { /** * Parse une string contenant un document XML dans un DOM Element. * * @param xml le document XML sous forme de string * @return l'element racine du document (root element), ou null si erreur * @throws IOException * @throws SAXException * @throws ParserConfigurationException */ public static Element stringToDomElement(final String xml) throws IOException, SAXException, ParserConfigurationException { Element element = null; if (xml != null) { final DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final Document doc = db.parse(new InputSource(new StringReader(xml))); element = doc.getDocumentElement(); } return element; } }