Wednesday, December 3, 2008

Convert a String into an Element

Convert a String into an InputStream

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

StringBuffer stringBuffer1 = new StringBuffer("2008-12-03T13:24:00.408+02:00");
ByteArrayInputStream bis1 = new ByteArrayInputStream(stringBuffer1.toString()
.getBytes("UTF-8"));

Convert an InputStream into Document
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(bis1);

As a result of Element

org.w3c.dom.Element messageElement = document.getDocumentElement();


No comments: