Code example for StringReader

0
    public static Document parseDocument(String input) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        Document doc;
        try { 
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(new InputSource(new StringReader(input)));
        } catch (ParserConfigurationException e) {
            throw new FilterException(e);
        } catch (SAXException e) {
            throw new FilterException(e);
        } catch (IOException e) {
            throw new FilterException(e);
        } 
        return doc;
    } 
 
    public static String writeDocument(Node input) throws TransformerException {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");