private void collapseFreetext(Node node, StringBuffer freetext, Set boxes) {
        int type = node.getNodeType();
        switch ( type ) {
            case Node.TEXT_NODE:
                freetext.append(node.getNodeValue());
                break;
            case Node.COMMENT_NODE:
                Comment comment = (Comment)node;
                if (Box.isBoundingBoxEncoding(comment.getNodeValue()))
                    boxes.add(Box.decode(comment.getNodeValue()));
                break;
            case Node.ELEMENT_NODE:
                String element = node.getNodeName();
                NodeList children = node.getChildNodes();
                int len = children.getLength();
                if (len>0) {
                    freetext.append(openTag(element));
                    for (int i=0; i<len; i++) {
                        collapseFreetext(children.item(i),freetext,boxes);
                    }
                    freetext.append(closeTag(element));
                }
                else freetext.append(leafTag(element));
                break;
        }
    }