public int print()

in empire-db/src/main/java/org/apache/empire/xml/XMLWriter.java [207:341]


    public int print(Node node, int level)
    {
        // is there anything to do?
        if (node == null)
        {
            return 0;
        }

        int type = node.getNodeType();
        switch (type)
        {
            // print document
            case Node.DOCUMENT_NODE:
            { // Sound not come here
                print(((Document) node).getDocumentElement(), 0);
            }
                break;
            // print element with attributes
            case Node.ELEMENT_NODE:
            {
                // out
                out.print('<');
                out.print(node.getNodeName());
                Attr attrs[] = sortAttributes(node.getAttributes());
                for (int i = 0; i < attrs.length; i++)
                {
                    Attr attr = attrs[i];
                    out.print(' ');
                    out.print(attr.getNodeName());
                    out.print("=\"");
                    out.print(normalize(attr.getNodeValue()));
                    out.print('"');
                }
                // children
                NodeList children = node.getChildNodes();
                if (children != null)
                {
                    // close-tag
                    int len = children.getLength();
                    if (len > 0 && children.item(0).getNodeType() != Node.TEXT_NODE)
                        out.println('>');
                    else
                        out.print('>');
                    // Print all Children
                    int prevType = 0;
                    for (int i = 0; i < len; i++)
                    {
                        if (i > 0 || children.item(i).getNodeType() != Node.TEXT_NODE)
                        { // Indent next Line
                            for (int s = 0; s < level; s++)
                                out.print(" ");
                        }
                        // Print a child
                        prevType = print(children.item(i), level + 1);
                    }
                    // Endtag
                    if (len > 0 && prevType != Node.TEXT_NODE)
                    { // padding
                        for (int s = 1; s < level; s++)
                            out.print(" ");
                    }
                    out.print("</");
                    out.print(node.getNodeName());
                    out.println('>');
                } 
                else
                    out.println("/>");
                break;
            }

            // handle entity reference nodes
            case Node.ENTITY_REFERENCE_NODE:
            {
                if (canonical)
                {
                    NodeList children = node.getChildNodes();
                    if (children != null)
                    {
                        int len = children.getLength();
                        for (int i = 0; i < len; i++)
                        {
                            print(children.item(i), level + 1);
                        }
                    }
                } 
                else
                {
                    out.print('&');
                    out.print(node.getNodeName());
                    out.print(';');
                }
                break;
            }

            // print cdata sections
            case Node.CDATA_SECTION_NODE:
            {
                if (canonical == false)
                {
                    out.print("<![CDATA[");
                    out.print(node.getNodeValue());
                    out.println("]]>");
                } 
                else
                    out.print(normalize(node.getNodeValue()));
                break;
            }

            // print text
            case Node.TEXT_NODE:
            { // Text
                out.print(normalize(node.getNodeValue()));
                break;
            }

            // print processing instruction
            case Node.PROCESSING_INSTRUCTION_NODE:
            {
                out.print("<?");
                out.print(node.getNodeName());
                String data = node.getNodeValue();
                if (data != null && data.length() > 0)
                {
                    out.print(' ');
                    out.print(data);
                }
                out.println("?>");
                break;
            }
        }

        out.flush();
        return type;

    } // print(Node)