class MsoRequest {

    public static String domToStr(Document doc) {
        if (doc == null) {
            return null;
        }

        try {
            StringWriter sw = new StringWriter();
            StreamResult sr = new StreamResult(sw);
            TransformerFactory tf = TransformerFactory.newInstance();
            tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
            tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
            Transformer t = tf.newTransformer();
            t.setOutputProperty(OutputKeys.STANDALONE, "yes");
            NodeList nl = doc.getDocumentElement().getChildNodes();
            DOMSource source = null;
            for (int x = 0; x < nl.getLength(); x++) {
                Node e = nl.item(x);
                if (e instanceof Element) {
                    source = new DOMSource(e);
                    break;
                }
            }
            if (source != null) {
                t.transform(source, sr);

                String s = sw.toString();
                return s;
            }

            return null;

        } catch (Exception e) {
            logger.error("Exception in domToStr", e);
        }
        return null;
    }

}