Example usage for org.w3c.dom ProcessingInstruction getTarget

List of usage examples for org.w3c.dom ProcessingInstruction getTarget

Introduction

In this page you can find the example usage for org.w3c.dom ProcessingInstruction getTarget.

Prototype

public String getTarget();

Source Link

Document

The target of this processing instruction.

Usage

From source file:Main.java

/**
 * Get ProcessingInstruction like String
 *///from   w w  w.  j  a  v a 2  s.  co  m
public static String processingInstructionToString(ProcessingInstruction pi) {
    return "<?" + pi.getTarget() + " " + pi.getData() + "?>";
}

From source file:DOMEdit.java

private static void outputProcessingInstructionNode(ProcessingInstruction node, String indent) {
    System.out.println(indent + "<?" + node.getTarget() + " " + node.getData() + "?>");
}

From source file:DOMCopy.java

private static void outputProcessingInstructionNode(ProcessingInstruction node, String indent) {
        System.out.println(indent + "<?" + node.getTarget() + " " + node.getData() + "?>");
    }

From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java

/**
 * @param xmlNode XML node//from  w  w  w  .j a  v  a 2 s .com
 * @param xmlStreamWriter XML stream writer
 * @throws XMLStreamException the XML stream exception
 */
public static void writeNode(Node xmlNode, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    if (xmlNode instanceof Element) {
        addElement((Element) xmlNode, xmlStreamWriter);
    } else if (xmlNode instanceof Text) {
        xmlStreamWriter.writeCharacters(xmlNode.getNodeValue());
    } else if (xmlNode instanceof CDATASection) {
        xmlStreamWriter.writeCData(((CDATASection) xmlNode).getData());
    } else if (xmlNode instanceof Comment) {
        xmlStreamWriter.writeComment(((Comment) xmlNode).getData());
    } else if (xmlNode instanceof EntityReference) {
        xmlStreamWriter.writeEntityRef(xmlNode.getNodeValue());
    } else if (xmlNode instanceof ProcessingInstruction) {
        ProcessingInstruction procInst = (ProcessingInstruction) xmlNode;
        xmlStreamWriter.writeProcessingInstruction(procInst.getTarget(), procInst.getData());
    } else if (xmlNode instanceof Document) {
        writeToDocument((Document) xmlNode, xmlStreamWriter);
    }
}

From source file:TreeDumper2.java

private void dumpProcessingInstructionNode(ProcessingInstruction node, String indent) {
    System.out.println(indent + "PI: target=" + node.getTarget());
    System.out.println(indent + "  " + node.getData());
}

From source file:XMLDocumentWriter.java

/**
 * Output the specified DOM Node object, printing it using the specified
 * indentation string/* www.j a v a2 s.  com*/
 */
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:fr.gouv.finances.dgfip.xemelios.utils.TextWriter.java

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

    writer.write("<?");
    writeText(writer, pi.getTarget());
    writer.write(" ");
    writeText(writer, pi.getData());
    writer.write("?>\n");
}

From source file:net.sourceforge.pmd.lang.xml.ast.DOMLineNumbers.java

private int determineLocation(Node n, int index) {
    int nextIndex = index;
    if (n.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        nextIndex = xmlString.indexOf("<!DOCTYPE", nextIndex);
    } else if (n.getNodeType() == Node.COMMENT_NODE) {
        nextIndex = xmlString.indexOf("<!--", nextIndex);
    } else if (n.getNodeType() == Node.ELEMENT_NODE) {
        nextIndex = xmlString.indexOf("<" + n.getNodeName(), nextIndex);
    } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) {
        nextIndex = xmlString.indexOf("<![CDATA[", nextIndex);
    } else if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        ProcessingInstruction pi = (ProcessingInstruction) n;
        nextIndex = xmlString.indexOf("<?" + pi.getTarget(), nextIndex);
    } else if (n.getNodeType() == Node.TEXT_NODE) {
        String te = unexpandEntities(n, n.getNodeValue());
        int newIndex = xmlString.indexOf(te, nextIndex);
        if (newIndex > 0) {
            nextIndex = newIndex;/*from w w  w. ja  va 2 s .  c o  m*/
        }
    } else if (n.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
        nextIndex = xmlString.indexOf("&" + n.getNodeName() + ";", nextIndex);
    }
    setBeginLocation(n, nextIndex);
    if (n.hasChildNodes()) {
        NodeList childs = n.getChildNodes();
        for (int i = 0; i < childs.getLength(); i++) {
            nextIndex = determineLocation(childs.item(i), nextIndex);
        }
    }
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        nextIndex += 2 + n.getNodeName().length() + 1; // </nodename>
    } else if (n.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        Node nextSibling = n.getNextSibling();
        if (nextSibling.getNodeType() == Node.ELEMENT_NODE) {
            nextIndex = xmlString.indexOf("<" + nextSibling.getNodeName(), nextIndex) - 1;
        } else if (nextSibling.getNodeType() == Node.COMMENT_NODE) {
            nextIndex = xmlString.indexOf("<!--", nextIndex);
        } else {
            nextIndex = xmlString.indexOf(">", nextIndex);
        }
    } else if (n.getNodeType() == Node.COMMENT_NODE) {
        nextIndex += 4 + 3; // <!-- and -->
        nextIndex += n.getNodeValue().length();
    } else if (n.getNodeType() == Node.TEXT_NODE) {
        String te = unexpandEntities(n, n.getNodeValue());
        nextIndex += te.length();
    } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) {
        nextIndex += "<![CDATA[".length() + n.getNodeValue().length() + "]]>".length();
    } else if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        ProcessingInstruction pi = (ProcessingInstruction) n;
        nextIndex += "<?".length() + pi.getTarget().length() + "?>".length() + pi.getData().length();
    }
    setEndLocation(n, nextIndex - 1);
    return nextIndex;
}