public static String withoutDeclaration(final Document document) {
        try {
            StringWriter out = new StringWriter();
            OutputFormat format = new OutputFormat();
            format.setSuppressDeclaration(true);
            format.setExpandEmptyElements(false);
            XMLWriter writer = new XMLWriter(out, format);

            writer.write(document);
            writer.flush();

            return out.toString();
        } catch (IOException e) {
            throw new RuntimeException("IOException while generating "
                + "textual representation: " + e.getMessage());
        }
    }
@Test
    public void ensureOpenElementCollapsedTest() throws Exception
    {
        // Setup test fixture.
        final Element open = DocumentHelper.createElement(QName.get("open", "urn:ietf:params:xml:ns:xmpp-framing"));
        final Document document = DocumentHelper.createDocument(open);
        document.setXMLEncoding(StandardCharsets.UTF_8.toString());
        open.addAttribute("from", "example.org");
        open.addAttribute("id", "unittest123");
        open.addAttribute(QName.get("lang", Namespace.XML_NAMESPACE), "en");
        open.addAttribute("version", "1.0");

        // Execute system under test.
        final String result = WebSocketClientStanzaHandler.withoutDeclaration(document);

        // Verify results.
        assertFalse(result.contains("></open>"));
    }