List of usage examples for org.w3c.dom ProcessingInstruction getData
public String getData();
From source file:Main.java
/** * Get ProcessingInstruction like String *//* w w w . j a v a 2 s . c o 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 ava2 s . c o m * @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:XMLDocumentWriter.java
/** * Output the specified DOM Node object, printing it using the specified * indentation string//from ww w .ja v a 2s . 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 dumpProcessingInstructionNode(ProcessingInstruction node, String indent) { System.out.println(indent + "PI: target=" + node.getTarget()); System.out.println(indent + " " + node.getData()); }
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 ww w .j av a 2s . co 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;//w w w . j a v a 2s . 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; }
From source file:org.eclipse.wst.xsl.xalan.debugger.XalanVariable.java
private String processNodeList(NodeList nodeList) { String value = ""; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node != null) { int nodeType = node.getNodeType(); if (node.getNodeType() == Node.ELEMENT_NODE) { value = createElement(value, node); }//from w w w . j a v a 2 s . c o m if (nodeType == Node.COMMENT_NODE) { value = value + "<!-- " + node.getNodeValue() + " -->"; } if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) { ProcessingInstruction pi = (ProcessingInstruction) node; value = value + "<?" + pi.getData() + " ?>"; } } } return value; }
From source file:org.openmrs.module.formentry.PublishInfoPath.java
private static void prepareTemplate(File tempDir, String fileName, String solutionVersion, String publishUrl, String namespace) {/*from w ww.java 2 s. com*/ File file = new File(tempDir, fileName); if (file == null) { log.warn("Missing file: '" + fileName + "'"); return; } if (log.isDebugEnabled()) log.debug("Preparing template: " + file.getAbsolutePath()); Document doc = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(file); // set namespace String tag = "form"; Element elem = getSingleElement(doc, tag); if (elem == null) { log.warn("Could not locate " + tag + " element in " + file.getName()); return; } elem.setAttribute("xmlns:openmrs", namespace); Node root = doc.getDocumentElement().getParentNode(); NodeList children = root.getChildNodes(); log.debug("Scanning for processing instructions"); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE && node.getNodeName().equals("mso-infoPathSolution")) { ProcessingInstruction pi = (ProcessingInstruction) node; String data = pi.getData(); if (log.isDebugEnabled()) log.debug(" found: " + data); data = data.replaceAll("(\\bsolutionVersion\\s*=\\s*\")[^\"]+\"", "$1" + solutionVersion + "\""); data = data.replaceAll("(\\bhref\\s*=\\s*\")[^\"]+\"", "$1" + publishUrl + "\""); if (log.isDebugEnabled()) log.debug(" replacing with: " + data); pi.setData(data); } } } catch (Exception e) { log.error("Trouble with file: " + fileName + " " + solutionVersion + " " + publishUrl, e); } writeXml(doc, file.getAbsolutePath()); }