org.w3c.dom.ProcessingInstruction Java Examples
The following examples show how to use
org.w3c.dom.ProcessingInstruction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XMLUtils.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Method getStrFromNode * * @param xpathnode * @return the string for the node. */ public static String getStrFromNode(Node xpathnode) { if (xpathnode.getNodeType() == Node.TEXT_NODE) { // we iterate over all siblings of the context node because eventually, // the text is "polluted" with pi's or comments StringBuilder sb = new StringBuilder(); for (Node currentSibling = xpathnode.getParentNode().getFirstChild(); currentSibling != null; currentSibling = currentSibling.getNextSibling()) { if (currentSibling.getNodeType() == Node.TEXT_NODE) { sb.append(((Text) currentSibling).getData()); } } return sb.toString(); } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) { return ((Attr) xpathnode).getNodeValue(); } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { return ((ProcessingInstruction) xpathnode).getNodeValue(); } return null; }
Example #2
Source File: XMLUtils.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Method getStrFromNode * * @param xpathnode * @return the string for the node. */ public static String getStrFromNode(Node xpathnode) { if (xpathnode.getNodeType() == Node.TEXT_NODE) { // we iterate over all siblings of the context node because eventually, // the text is "polluted" with pi's or comments StringBuilder sb = new StringBuilder(); for (Node currentSibling = xpathnode.getParentNode().getFirstChild(); currentSibling != null; currentSibling = currentSibling.getNextSibling()) { if (currentSibling.getNodeType() == Node.TEXT_NODE) { sb.append(((Text) currentSibling).getData()); } } return sb.toString(); } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) { return ((Attr) xpathnode).getNodeValue(); } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { return ((ProcessingInstruction) xpathnode).getNodeValue(); } return null; }
Example #3
Source File: DOMScanner.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private void visit( Node n ) throws SAXException { setCurrentLocation( n ); // if a case statement gets too big, it should be made into a separate method. switch(n.getNodeType()) { case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String value = n.getNodeValue(); receiver.characters( value.toCharArray(), 0, value.length() ); break; case Node.ELEMENT_NODE: visit( (Element)n ); break; case Node.ENTITY_REFERENCE_NODE: receiver.skippedEntity(n.getNodeName()); break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi = (ProcessingInstruction)n; receiver.processingInstruction(pi.getTarget(),pi.getData()); break; } }
Example #4
Source File: DomToGroovy.java From groovy with Apache License 2.0 | 6 votes |
protected void print(Node node, Map namespaces, boolean endWithComma) { switch (node.getNodeType()) { case Node.ELEMENT_NODE : printElement((Element) node, namespaces, endWithComma); break; case Node.PROCESSING_INSTRUCTION_NODE : printPI((ProcessingInstruction) node, endWithComma); break; case Node.TEXT_NODE : printText((Text) node, endWithComma); break; case Node.COMMENT_NODE : printComment((Comment) node, endWithComma); break; } }
Example #5
Source File: HtmlPage.java From htmlunit with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override protected void checkChildHierarchy(final org.w3c.dom.Node newChild) throws DOMException { if (newChild instanceof Element) { if (getDocumentElement() != null) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may only have a single child Element."); } } else if (newChild instanceof DocumentType) { if (getDoctype() != null) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may only have a single child DocumentType."); } } else if (!(newChild instanceof Comment || newChild instanceof ProcessingInstruction)) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may not have a child of this type: " + newChild.getNodeType()); } super.checkChildHierarchy(newChild); }
Example #6
Source File: DOMScanner.java From hottub with GNU General Public License v2.0 | 6 votes |
private void visit( Node n ) throws SAXException { setCurrentLocation( n ); // if a case statement gets too big, it should be made into a separate method. switch(n.getNodeType()) { case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String value = n.getNodeValue(); receiver.characters( value.toCharArray(), 0, value.length() ); break; case Node.ELEMENT_NODE: visit( (Element)n ); break; case Node.ENTITY_REFERENCE_NODE: receiver.skippedEntity(n.getNodeName()); break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi = (ProcessingInstruction)n; receiver.processingInstruction(pi.getTarget(),pi.getData()); break; } }
Example #7
Source File: test_DifferenceEngine.java From xmlunit with Apache License 2.0 | 6 votes |
public void testCompareProcessingInstruction() throws Exception { String[] expected = PROC_A; String[] actual = PROC_B; ProcessingInstruction control = document.createProcessingInstruction( expected[0], expected[1]); ProcessingInstruction test = document.createProcessingInstruction( actual[0], actual[1]); assertDifferentProcessingInstructions(control, test, PROCESSING_INSTRUCTION_TARGET); ProcessingInstruction control2 = document.createProcessingInstruction( expected[0], expected[1]); ProcessingInstruction test2 = document.createProcessingInstruction( expected[0], actual[1]); assertDifferentProcessingInstructions(control2, test2, PROCESSING_INSTRUCTION_DATA); }
Example #8
Source File: XmlNode.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
String ecmaValue() { // TODO See ECMA 357 Section 9.1 if (isTextType()) { return ((org.w3c.dom.Text)dom).getData(); } else if (isAttributeType()) { return ((org.w3c.dom.Attr)dom).getValue(); } else if (isProcessingInstructionType()) { return ((org.w3c.dom.ProcessingInstruction)dom).getData(); } else if (isCommentType()) { return ((org.w3c.dom.Comment)dom).getNodeValue(); } else if (isElementType()) { throw new RuntimeException("Unimplemented ecmaValue() for elements."); } else { throw new RuntimeException("Unimplemented for node " + dom); } }
Example #9
Source File: NodesTest.java From caja with Apache License 2.0 | 6 votes |
public final void testProcessingInstructionInHtml() { Document doc = DomParser.makeDocument(null, null); ProcessingInstruction pi = doc.createProcessingInstruction( "foo", "<script>alert(1)</script>"); Element el = doc.createElementNS(Namespaces.HTML_NAMESPACE_URI, "div"); el.appendChild(pi); assertEquals( "<div><?foo <script>alert(1)</script>?></div>", Nodes.render(el, MarkupRenderMode.XML)); try { Nodes.render(el, MarkupRenderMode.HTML); } catch (UncheckedUnrenderableException ex) { // OK return; } fail("Rendered in html"); }
Example #10
Source File: DOMScanner.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private void visit( Node n ) throws SAXException { setCurrentLocation( n ); // if a case statement gets too big, it should be made into a separate method. switch(n.getNodeType()) { case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String value = n.getNodeValue(); receiver.characters( value.toCharArray(), 0, value.length() ); break; case Node.ELEMENT_NODE: visit( (Element)n ); break; case Node.ENTITY_REFERENCE_NODE: receiver.skippedEntity(n.getNodeName()); break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi = (ProcessingInstruction)n; receiver.processingInstruction(pi.getTarget(),pi.getData()); break; } }
Example #11
Source File: SAX2DOM.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * adds processing instruction node to DOM. */ public void processingInstruction(String target, String data) { appendTextNode(); final Node last = (Node)_nodeStk.peek(); ProcessingInstruction pi = _document.createProcessingInstruction( target, data); if (pi != null){ if (last == _root && _nextSibling != null) last.insertBefore(pi, _nextSibling); else last.appendChild(pi); _lastSibling = pi; } }
Example #12
Source File: JAXRSClientServerSpringBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetWadlFromWadlLocation() throws Exception { String address = "http://localhost:" + PORT + "/the/generated"; WebClient client = WebClient.create(address + "/bookstore" + "?_wadl&_type=xml"); Document doc = StaxUtils.read(new InputStreamReader(client.get(InputStream.class), StandardCharsets.UTF_8)); List<Element> resources = checkWadlResourcesInfo(doc, address, "/schemas/book.xsd", 2); assertEquals("", resources.get(0).getAttribute("type")); String type = resources.get(1).getAttribute("type"); String resourceTypeAddress = address + "/bookstoreImportResourceType.wadl#bookstoreType"; assertEquals(resourceTypeAddress, type); checkSchemas(address, "/schemas/book.xsd", "/schemas/chapter.xsd", "include"); checkSchemas(address, "/schemas/chapter.xsd", null, null); // check resource type resource checkWadlResourcesType(address, resourceTypeAddress, "/schemas/book.xsd"); String templateRef = null; NodeList nd = doc.getChildNodes(); for (int i = 0; i < nd.getLength(); i++) { Node n = nd.item(i); if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { String piData = ((ProcessingInstruction)n).getData(); int hRefStart = piData.indexOf("href=\""); if (hRefStart > 0) { int hRefEnd = piData.indexOf("\"", hRefStart + 6); templateRef = piData.substring(hRefStart + 6, hRefEnd); } } } assertNotNull(templateRef); WebClient client2 = WebClient.create(templateRef); WebClient.getConfig(client2).getHttpConduit().getClient().setReceiveTimeout(1000000L); String template = client2.get(String.class); assertNotNull(template); assertTrue(template.indexOf("<xsl:stylesheet") != -1); }
Example #13
Source File: DOMPrinter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #14
Source File: DOMPrinter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #15
Source File: XmlNode.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
final void setLocalName(String localName) { if (dom instanceof ProcessingInstruction) { setProcessingInstructionName(localName); } else { String prefix = dom.getPrefix(); if (prefix == null) prefix = ""; this.dom = dom.getOwnerDocument().renameNode(dom, dom.getNamespaceURI(), QName.qualify(prefix, localName)); } }
Example #16
Source File: SAX2DOM.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * adds processing instruction node to DOM. */ public void processingInstruction(String target, String data) { appendTextNode(); final Node last = (Node)_nodeStk.peek(); ProcessingInstruction pi = _document.createProcessingInstruction( target, data); if (pi != null){ if (last == _root && _nextSibling != null) last.insertBefore(pi, _nextSibling); else last.appendChild(pi); _lastSibling = pi; } }
Example #17
Source File: DOMDifferenceEngineTest.java From xmlunit with Apache License 2.0 | 5 votes |
@Test public void compareProcessingInstructions() { DOMDifferenceEngine d = new DOMDifferenceEngine(); DiffExpecter ex = new DiffExpecter(ComparisonType.PROCESSING_INSTRUCTION_TARGET); d.addDifferenceListener(ex); d.setComparisonController(ComparisonControllers.StopWhenDifferent); ProcessingInstruction foo1 = doc.createProcessingInstruction("foo", "1"); ProcessingInstruction bar1 = doc.createProcessingInstruction("bar", "1"); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(foo1, new XPathContext(), foo1, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(foo1, new XPathContext(), bar1, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); ex = new DiffExpecter(ComparisonType.PROCESSING_INSTRUCTION_DATA); d.addDifferenceListener(ex); d.setComparisonController(ComparisonControllers.StopWhenDifferent); ProcessingInstruction foo2 = doc.createProcessingInstruction("foo", "2"); assertEquals(wrap(ComparisonResult.EQUAL), d.compareNodes(foo1, new XPathContext(), foo1, new XPathContext())); assertEquals(wrapAndStop(ComparisonResult.DIFFERENT), d.compareNodes(foo1, new XPathContext(), foo2, new XPathContext())); assertEquals(1, ex.invoked); }
Example #18
Source File: XmlNode.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
static Filter PROCESSING_INSTRUCTION(final XMLName name) { return new Filter() { @Override boolean accept(Node node) { if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { ProcessingInstruction pi = (ProcessingInstruction)node; return name.matchesLocalName(pi.getTarget()); } return false; } }; }
Example #19
Source File: XMLDOMWriterImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * is not supported in this release. * @param target {@inheritDoc} * @throws javax.xml.stream.XMLStreamException {@inheritDoc} */ public void writeProcessingInstruction(String target) throws XMLStreamException { if(target == null){ throw new XMLStreamException("Target cannot be null"); } ProcessingInstruction pi = ownerDoc.createProcessingInstruction(target, ""); currentNode.appendChild(pi); }
Example #20
Source File: DOMPrinter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #21
Source File: XMLDOMWriterImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * is not supported in this release. * @param target {@inheritDoc} * @throws javax.xml.stream.XMLStreamException {@inheritDoc} */ public void writeProcessingInstruction(String target) throws XMLStreamException { if(target == null){ throw new XMLStreamException("Target cannot be null"); } ProcessingInstruction pi = ownerDoc.createProcessingInstruction(target, ""); currentNode.appendChild(pi); }
Example #22
Source File: Bug6354955.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void testPINode() { try { Document xmlDocument = createNewDocument(); ProcessingInstruction piNode = xmlDocument.createProcessingInstruction("execute", "test"); String outerXML = getOuterXML(piNode); System.out.println("OuterXML of Comment Node is:" + outerXML); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception occured: " + e.getMessage()); } }
Example #23
Source File: PITest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void test() throws Exception { Document document = createDOMWithNS("PITest01.xml"); ProcessingInstruction pi = document.createProcessingInstruction("PI", "processing"); assertEquals(pi.getData(), "processing"); assertEquals(pi.getTarget(), "PI"); pi.setData("newProcessing"); assertEquals(pi.getData(), "newProcessing"); }
Example #24
Source File: XmlNode.java From astor with GNU General Public License v2.0 | 5 votes |
final void setLocalName(String localName) { if (dom instanceof ProcessingInstruction) { setProcessingInstructionName(localName); } else { String prefix = dom.getPrefix(); if (prefix == null) prefix = ""; this.dom = dom.getOwnerDocument().renameNode(dom, dom.getNamespaceURI(), QName.qualify(prefix, localName)); } }
Example #25
Source File: SAX2DOM.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * adds processing instruction node to DOM. */ public void processingInstruction(String target, String data) { appendTextNode(); final Node last = (Node)_nodeStk.peek(); ProcessingInstruction pi = _document.createProcessingInstruction( target, data); if (pi != null){ if (last == _root && _nextSibling != null) last.insertBefore(pi, _nextSibling); else last.appendChild(pi); _lastSibling = pi; } }
Example #26
Source File: DOMPrinter.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example #27
Source File: XhtmlGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void writeNodePlain(Writer out, Node node, int level) throws FHIRException, DOMException, IOException { if (node.getNodeType() == Node.ELEMENT_NODE) writeElementPlain(out, (Element) node, level); else if (node.getNodeType() == Node.TEXT_NODE) writeTextPlain(out, (Text) node, level); else if (node.getNodeType() == Node.COMMENT_NODE) writeCommentPlain(out, (Comment) node, level); else if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) writeProcessingInstructionPlain(out, (ProcessingInstruction) node); else if (node.getNodeType() != Node.ATTRIBUTE_NODE) throw new FHIRException("Unhandled node type"); }
Example #28
Source File: DOMStreamReader.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public String getPITarget() { if (_state == PROCESSING_INSTRUCTION) { return ((ProcessingInstruction) _current).getTarget(); } return null; }
Example #29
Source File: DOMWriter.java From exificient with MIT License | 4 votes |
protected void encodeChildNodes(NodeList children) throws EXIException, IOException { for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); switch (n.getNodeType()) { case Node.ELEMENT_NODE: encodeNode(n); break; case Node.ATTRIBUTE_NODE: break; case Node.TEXT_NODE: exiBody.encodeCharacters(new StringValue(n.getNodeValue())); break; case Node.COMMENT_NODE: if (preserveComments) { String c = n.getNodeValue(); exiBody.encodeComment(c.toCharArray(), 0, c.length()); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType dt = (DocumentType) n; String publicID = dt.getPublicId() == null ? "" : dt .getPublicId(); String systemID = dt.getSystemId() == null ? "" : dt .getSystemId(); String text = dt.getInternalSubset() == null ? "" : dt .getInternalSubset(); exiBody.encodeDocType(dt.getName(), publicID, systemID, text); break; case Node.ENTITY_REFERENCE_NODE: // checkPendingChars(); // TODO ER break; case Node.CDATA_SECTION_NODE: // String cdata = n.getNodeValue(); // exiBody.encodeCharacters(new // StringValue(Constants.CDATA_START // + cdata + Constants.CDATA_END)); exiBody.encodeCharacters(new StringValue(n.getNodeValue())); break; case Node.PROCESSING_INSTRUCTION_NODE: if (preservePIs) { ProcessingInstruction pi = (ProcessingInstruction) n; exiBody.encodeProcessingInstruction(pi.getTarget(), pi.getData()); } break; default: System.err.println("[WARNING] Unhandled DOM NodeType: " + n.getNodeType()); // throw new EXIException("Unknown NodeType? " + // n.getNodeType()); } } }
Example #30
Source File: DOMStreamReader.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public String getPITarget() { if (_state == PROCESSING_INSTRUCTION) { return ((ProcessingInstruction) _current).getTarget(); } return null; }