Example usage for org.w3c.dom Comment getData

List of usage examples for org.w3c.dom Comment getData

Introduction

In this page you can find the example usage for org.w3c.dom Comment getData.

Prototype

public String getData() throws DOMException;

Source Link

Document

The character data of the node that implements this interface.

Usage

From source file:Main.java

static void printElement(Element element, String indent) {
    System.out.println("Element '" + element.getNodeName() + "'");
    NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        switch (child.getNodeType()) {
        case Node.ELEMENT_NODE:
            printElement((Element) child, indent + "\t");
            break;
        case Node.ATTRIBUTE_NODE:
            Attr attr = (Attr) child;
            System.out.println("\tAttribute: '" + attr.getName() + "' = '" + attr.getValue() + "'");
            break;
        case Node.COMMENT_NODE:
            Comment comment = (Comment) child;
            System.out.println("\tComment: '" + comment.getData() + "'");
            break;
        case Node.CDATA_SECTION_NODE:
            CharacterData cdata = (CharacterData) child;
            System.out.println("\tCDatat: '" + cdata.getData() + "'");
            break;
        case Node.TEXT_NODE:
            Text text = (Text) child;
            System.out.println("\tText: '" + text.getData() + "'");
            break;
        default://from  ww  w .j  av a  2  s .  c o  m
            System.out.println("\tUnknown node type: '" + child.getNodeType() + "'");
            break;
        }
    }
}

From source file:DOMEdit.java

private static void outputComment(Comment node, String indent) {
    System.out.println(indent + "<!-- " + node.getData() + " -->");
}

From source file:DOMCopy.java

private static void outputComment(Comment node, String indent) {
        System.out.println(indent + "<!-- " + node.getData() + " -->");
    }

From source file:XMLDocumentWriter.java

/**
 * Output the specified DOM Node object, printing it using the specified
 * indentation string/* w ww. j  a  v  a 2  s.  c o m*/
 */
public void write(Node node, String indent) {
    // The output depends on the type of the node
    switch (node.getNodeType()) {
    case Node.DOCUMENT_NODE: { // If its a Document node
        Document doc = (Document) node;
        out.println(indent + "<?xml version='1.0'?>"); // Output header
        Node child = doc.getFirstChild(); // Get the first node
        while (child != null) { // Loop 'till no more nodes
            write(child, indent); // Output node
            child = child.getNextSibling(); // Get next node
        }
        break;
    }
    case Node.DOCUMENT_TYPE_NODE: { // It is a <!DOCTYPE> tag
        DocumentType doctype = (DocumentType) node;
        // Note that the DOM Level 1 does not give us information about
        // the the public or system ids of the doctype, so we can't output
        // a complete <!DOCTYPE> tag here. We can do better with Level 2.
        out.println("<!DOCTYPE " + doctype.getName() + ">");
        break;
    }
    case Node.ELEMENT_NODE: { // Most nodes are Elements
        Element elt = (Element) node;
        out.print(indent + "<" + elt.getTagName()); // Begin start tag
        NamedNodeMap attrs = elt.getAttributes(); // Get attributes
        for (int i = 0; i < attrs.getLength(); i++) { // Loop through them
            Node a = attrs.item(i);
            out.print(" " + a.getNodeName() + "='" + // Print attr. name
                    fixup(a.getNodeValue()) + "'"); // Print attr. value
        }
        out.println(">"); // Finish start tag

        String newindent = indent + "    "; // Increase indent
        Node child = elt.getFirstChild(); // Get child
        while (child != null) { // Loop
            write(child, newindent); // Output child
            child = child.getNextSibling(); // Get next child
        }

        out.println(indent + "</" + // Output end tag
                elt.getTagName() + ">");
        break;
    }
    case Node.TEXT_NODE: { // Plain text node
        Text textNode = (Text) node;
        String text = textNode.getData().trim(); // Strip off space
        if ((text != null) && text.length() > 0) // If non-empty
            out.println(indent + fixup(text)); // print text
        break;
    }
    case Node.PROCESSING_INSTRUCTION_NODE: { // Handle PI nodes
        ProcessingInstruction pi = (ProcessingInstruction) node;
        out.println(indent + "<?" + pi.getTarget() + " " + pi.getData() + "?>");
        break;
    }
    case Node.ENTITY_REFERENCE_NODE: { // Handle entities
        out.println(indent + "&" + node.getNodeName() + ";");
        break;
    }
    case Node.CDATA_SECTION_NODE: { // Output CDATA sections
        CDATASection cdata = (CDATASection) node;
        // Careful! Don't put a CDATA section in the program itself!
        out.println(indent + "<" + "![CDATA[" + cdata.getData() + "]]" + ">");
        break;
    }
    case Node.COMMENT_NODE: { // Comments
        Comment c = (Comment) node;
        out.println(indent + "<!--" + c.getData() + "-->");
        break;
    }
    default: // Hopefully, this won't happen too much!
        System.err.println("Ignoring node: " + node.getClass().getName());
        break;
    }
}

From source file:TreeDumper2.java

private void dumpCommentNode(Comment node, String indent) {
    System.out.println(indent + "COMMENT length=" + node.getLength());
    System.out.println(indent + "  " + node.getData());
}

From source file:fr.gouv.finances.dgfip.xemelios.utils.TextWriter.java

private void comment(Writer writer, Comment comment) throws IOException {
    if (prettyPrint) {
        checkTextBuffer(writer);//from   ww w .  j a v a2 s  . c o  m
        indent(writer);
    }

    writer.write("<!--");
    writeText(writer, comment.getData());
    writer.write("-->");

    if (prettyPrint)
        writer.write('\n');
}