public static void write(final INode node, final Writer writer) throws IOException {

        if (node == null) {
            return;
        }

        if (node instanceof Text) {
            writeText((Text)node, writer);
            return;
        }
        if (node instanceof Element) {
            writeElement((Element)node, writer);
            return;
        }
        if (node instanceof Comment) {
            writeComment((Comment)node, writer);
            return;
        }
        if (node instanceof CDATASection) {
            writeCDATASection((CDATASection)node, writer);
            return;
        }
        if (node instanceof DocType) {
            writeDocType((DocType)node, writer);
            return;
        }
        if (node instanceof Document) {
            writeDocument((Document)node, writer);
            return;
        }
        if (node instanceof XmlDeclaration) {
            writeXmlDeclaration((XmlDeclaration)node, writer);
            return;
        }
        if (node instanceof ProcessingInstruction) {
            writeProcessingInstruction((ProcessingInstruction)node, writer);
            return;
        }

    }