Mercurial > hg > FederatedLinda
view src/fdl/test/debug/XMLBuilder.java @ 91:4df1d50df52a
Ring: fdl.test.debug
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 16 Feb 2010 03:58:06 +0900 |
parents | c0575f877591 |
children |
line wrap: on
line source
package fdl.test.debug; import java.io.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.*; public class XMLBuilder { protected Document document; protected Transformer transformer; public XMLBuilder() { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = null; try { docBuilder = dbFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); } document = docBuilder.newDocument(); TransformerFactory tFactory = TransformerFactory.newInstance(); try { transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); } catch (TransformerConfigurationException e) { e.printStackTrace(); } } public String createXML() { StringWriter sw = new StringWriter(); try { transformer.transform(new DOMSource(document), new StreamResult(sw)); } catch (TransformerException e) { e.printStackTrace(); } return sw.toString(); } }