Convert String into InputStream
In the last days I was asked several times: “How do I convert a string into an InputStream, so that I can parse my XML-String with the SAX parser?” (note: or any other XML-Parser like DOM, JAXP, JDOM, …).
Being tired of explaining the same thing again and again – here is the answer:
1 2 3 4 5 6 7 | String myString = 'content of your very own string'; ByteArrayInputStream in = new ByteArrayInputStream(myString.getBytes()); InputSource is = new InputSource(); is.setByteStream(in); Parser myParser = new Parser(); myParser.parse(is); |
Quick & Easy