Bonjour,
J'aimerai convertir un objet de type Document en chaîne de caractère simple (String).
Merci.
Version imprimable
Bonjour,
J'aimerai convertir un objet de type Document en chaîne de caractère simple (String).
Merci.
J'ai trouvé la réponse :
=======>
public String getStringFromDocument(Document doc)
{
try
{
JDOMSource domSource = new JDOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
return writer.toString();
}
catch(TransformerException ex)
{
ex.printStackTrace();
return null;
}
}
et ça marche!!!!!!!!
Ouais.... Il y avait ça aussi :
Code:
1
2
3
4
5
6
7
8 try { StringWriter writer = new StringWriter(); new XMLOutputter().output(doc, writer); return writer.toString(); } catch (IOException e) { // That should not be possible with a StringWriter throw new IllegalStateException(e.getMessage(), e); }