Java Code Examples for javax.xml.stream.XMLStreamWriter#writeProcessingInstruction()
The following examples show how to use
javax.xml.stream.XMLStreamWriter#writeProcessingInstruction() .
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: EwsServiceXmlWriter.java From ews-java-api with MIT License | 6 votes |
/** * @param xmlNode XML node * @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); } }
Example 2
Source File: XmiMappingWriter.java From secure-data-service with Apache License 2.0 | 6 votes |
private static final void writeMappingDocument(final XmiComparison documentElement, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeProcessingInstruction("xml-stylesheet", "type='text/xsl' href='xmi-mapping.xsl'"); xsw.setPrefix("", XmiMappingConstants.NAMESPACE_URI); xsw.writeStartElement(XmiMappingConstants.DOCUMENT_ELEMENT.getLocalPart()); xsw.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); xsw.writeAttribute("xsi", "http://www.w3.org/2001/XMLSchema-instance", "noNamespaceSchemaLocation", "xmi-mapping.xsd"); try { writeReference(documentElement.getLhsDef(), XmiMappingConstants.LHS_MODEL, xsw); writeReference(documentElement.getRhsDef(), XmiMappingConstants.RHS_MODEL, xsw); for (final XmiMapping mapping : documentElement.getMappings()) { writeMapping(mapping, xsw); } } finally { xsw.writeEndElement(); } }
Example 3
Source File: DOMUtil.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Traverses a DOM node and writes out on a streaming writer. * * @param node * @param writer */ public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException { writeTagWithAttributes(node, writer); if (node.hasChildNodes()) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); switch (child.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: writer.writeProcessingInstruction(child.getNodeValue()); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.CDATA_SECTION_NODE: writer.writeCData(child.getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(child.getNodeValue()); break; case Node.TEXT_NODE: writer.writeCharacters(child.getNodeValue()); break; case Node.ELEMENT_NODE: serializeNode((Element) child, writer); break; default: break; } } } writer.writeEndElement(); }
Example 4
Source File: DOMUtil.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Traverses a DOM node and writes out on a streaming writer. * * @param node * @param writer */ public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException { writeTagWithAttributes(node, writer); if (node.hasChildNodes()) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); switch (child.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: writer.writeProcessingInstruction(child.getNodeValue()); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.CDATA_SECTION_NODE: writer.writeCData(child.getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(child.getNodeValue()); break; case Node.TEXT_NODE: writer.writeCharacters(child.getNodeValue()); break; case Node.ELEMENT_NODE: serializeNode((Element) child, writer); break; default: break; } } } writer.writeEndElement(); }
Example 5
Source File: DOMUtil.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Traverses a DOM node and writes out on a streaming writer. * * @param node * @param writer */ public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException { writeTagWithAttributes(node, writer); if (node.hasChildNodes()) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); switch (child.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: writer.writeProcessingInstruction(child.getNodeValue()); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.CDATA_SECTION_NODE: writer.writeCData(child.getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(child.getNodeValue()); break; case Node.TEXT_NODE: writer.writeCharacters(child.getNodeValue()); break; case Node.ELEMENT_NODE: serializeNode((Element) child, writer); break; default: break; } } } writer.writeEndElement(); }
Example 6
Source File: DOMUtil.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Traverses a DOM node and writes out on a streaming writer. * * @param node * @param writer */ public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException { writeTagWithAttributes(node, writer); if (node.hasChildNodes()) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); switch (child.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: writer.writeProcessingInstruction(child.getNodeValue()); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.CDATA_SECTION_NODE: writer.writeCData(child.getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(child.getNodeValue()); break; case Node.TEXT_NODE: writer.writeCharacters(child.getNodeValue()); break; case Node.ELEMENT_NODE: serializeNode((Element) child, writer); break; default: break; } } } writer.writeEndElement(); }
Example 7
Source File: DOMUtil.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Traverses a DOM node and writes out on a streaming writer. * * @param node * @param writer */ public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException { writeTagWithAttributes(node, writer); if (node.hasChildNodes()) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); switch (child.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: writer.writeProcessingInstruction(child.getNodeValue()); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.CDATA_SECTION_NODE: writer.writeCData(child.getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(child.getNodeValue()); break; case Node.TEXT_NODE: writer.writeCharacters(child.getNodeValue()); break; case Node.ELEMENT_NODE: serializeNode((Element) child, writer); break; default: break; } } } writer.writeEndElement(); }
Example 8
Source File: DOMUtil.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Traverses a DOM node and writes out on a streaming writer. * * @param node * @param writer */ public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException { writeTagWithAttributes(node, writer); if (node.hasChildNodes()) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); switch (child.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: writer.writeProcessingInstruction(child.getNodeValue()); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.CDATA_SECTION_NODE: writer.writeCData(child.getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(child.getNodeValue()); break; case Node.TEXT_NODE: writer.writeCharacters(child.getNodeValue()); break; case Node.ELEMENT_NODE: serializeNode((Element) child, writer); break; default: break; } } } writer.writeEndElement(); }
Example 9
Source File: DOMUtil.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Traverses a DOM node and writes out on a streaming writer. * * @param node * @param writer */ public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException { writeTagWithAttributes(node, writer); if (node.hasChildNodes()) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); switch (child.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: writer.writeProcessingInstruction(child.getNodeValue()); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.CDATA_SECTION_NODE: writer.writeCData(child.getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(child.getNodeValue()); break; case Node.TEXT_NODE: writer.writeCharacters(child.getNodeValue()); break; case Node.ELEMENT_NODE: serializeNode((Element) child, writer); break; default: break; } } } writer.writeEndElement(); }
Example 10
Source File: DOMUtil.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Traverses a DOM node and writes out on a streaming writer. * * @param node * @param writer */ public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException { writeTagWithAttributes(node, writer); if (node.hasChildNodes()) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); switch (child.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: writer.writeProcessingInstruction(child.getNodeValue()); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.CDATA_SECTION_NODE: writer.writeCData(child.getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(child.getNodeValue()); break; case Node.TEXT_NODE: writer.writeCharacters(child.getNodeValue()); break; case Node.ELEMENT_NODE: serializeNode((Element) child, writer); break; default: break; } } } writer.writeEndElement(); }
Example 11
Source File: StaxUtils.java From cxf with Apache License 2.0 | 4 votes |
public static void writeNode(Node n, XMLStreamWriter writer, boolean repairing) throws XMLStreamException { switch (n.getNodeType()) { case Node.ELEMENT_NODE: writeElement((Element)n, writer, repairing); break; case Node.TEXT_NODE: writer.writeCharacters(((Text)n).getNodeValue()); break; case Node.COMMENT_NODE: writer.writeComment(((Comment)n).getData()); break; case Node.CDATA_SECTION_NODE: writer.writeCData(((CDATASection)n).getData()); break; case Node.ENTITY_REFERENCE_NODE: writer.writeEntityRef(((EntityReference)n).getNodeValue()); break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi = (ProcessingInstruction)n; writer.writeProcessingInstruction(pi.getTarget(), pi.getData()); break; case Node.DOCUMENT_NODE: writeDocument((Document)n, writer, repairing); break; case Node.DOCUMENT_FRAGMENT_NODE: { DocumentFragment frag = (DocumentFragment)n; Node child = frag.getFirstChild(); while (child != null) { writeNode(child, writer, repairing); child = child.getNextSibling(); } break; } case Node.DOCUMENT_TYPE_NODE: try { if (((DocumentType)n).getTextContent() != null) { writer.writeDTD(((DocumentType)n).getTextContent()); } } catch (UnsupportedOperationException ex) { //can we ignore? DOM writers really don't allow this //as there isn't a way to write a DTD in dom } break; default: throw new IllegalStateException("Found type: " + n.getClass().getName()); } }
Example 12
Source File: StaxUtils.java From cxf with Apache License 2.0 | 4 votes |
public static void writeEvent(XMLEvent event, XMLStreamWriter writer) throws XMLStreamException { switch (event.getEventType()) { case XMLStreamConstants.START_ELEMENT: writeStartElementEvent(event, writer); break; case XMLStreamConstants.END_ELEMENT: writer.writeEndElement(); break; case XMLStreamConstants.ATTRIBUTE: writeAttributeEvent(event, writer); break; case XMLStreamConstants.ENTITY_REFERENCE: writer.writeEntityRef(((javax.xml.stream.events.EntityReference)event).getName()); break; case XMLStreamConstants.DTD: writer.writeDTD(((DTD)event).getDocumentTypeDeclaration()); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: if (((javax.xml.stream.events.ProcessingInstruction)event).getData() != null) { writer.writeProcessingInstruction( ((javax.xml.stream.events.ProcessingInstruction)event).getTarget(), ((javax.xml.stream.events.ProcessingInstruction)event).getData()); } else { writer.writeProcessingInstruction( ((javax.xml.stream.events.ProcessingInstruction)event).getTarget()); } break; case XMLStreamConstants.NAMESPACE: if (((Namespace)event).isDefaultNamespaceDeclaration()) { writer.writeDefaultNamespace(((Namespace)event).getNamespaceURI()); writer.setDefaultNamespace(((Namespace)event).getNamespaceURI()); } else { writer.writeNamespace(((Namespace)event).getPrefix(), ((Namespace)event).getNamespaceURI()); writer.setPrefix(((Namespace)event).getPrefix(), ((Namespace)event).getNamespaceURI()); } break; case XMLStreamConstants.COMMENT: writer.writeComment(((javax.xml.stream.events.Comment)event).getText()); break; case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: writer.writeCharacters(event.asCharacters().getData()); break; case XMLStreamConstants.CDATA: writer.writeCData(event.asCharacters().getData()); break; case XMLStreamConstants.START_DOCUMENT: if (((StartDocument)event).encodingSet()) { writer.writeStartDocument(((StartDocument)event).getCharacterEncodingScheme(), ((StartDocument)event).getVersion()); } else { writer.writeStartDocument(((StartDocument)event).getVersion()); } break; case XMLStreamConstants.END_DOCUMENT: writer.writeEndDocument(); break; default: //shouldn't get here } }
Example 13
Source File: WadlWriter.java From secure-data-service with Apache License 2.0 | 4 votes |
private static final void writeProcessingInstruction(final DmProcessingInstruction pi, final XMLStreamWriter xsw) throws XMLStreamException { xsw.writeProcessingInstruction(pi.getName().getLocalPart(), pi.getStringValue()); }