List of usage examples for javax.xml.stream XMLStreamWriter writeCData
public void writeCData(String data) throws XMLStreamException;
From source file:MainClass.java
public static void main(String[] args) throws XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.writeStartDocument("1.0"); writer.writeStartElement("http://www.t.com/f", "sample"); writer.writeAttribute("attribute", "true"); writer.writeAttribute("http://www.t.com/f", "attribute2", "false"); writer.writeCharacters("some text"); writer.writeCData("<test>"); writer.writeEndElement();//from ww w . ja v a 2s.c om writer.writeEndDocument(); writer.flush(); }
From source file:Main.java
public static void writeTag(XMLStreamWriter xmlWriter, String tag, Object value) throws XMLStreamException { if (value == null) { xmlWriter.writeEmptyElement(tag); } else {/*from ww w . j a v a 2 s.co m*/ xmlWriter.writeStartElement(tag); xmlWriter.writeCData(value.toString()); xmlWriter.writeEndElement(); } }
From source file:com.flexive.shared.FxXMLUtils.java
/** * Write a "simple" tag/* w w w . jav a2s. c o m*/ * * @param writer xml writer * @param tag tag name * @param value value * @param asCData use CDData? * @throws javax.xml.stream.XMLStreamException * on errors */ public static void writeSimpleTag(XMLStreamWriter writer, String tag, Object value, boolean asCData) throws XMLStreamException { writer.writeStartElement(tag); if (asCData) writer.writeCData(String.valueOf(value)); else writer.writeCharacters(String.valueOf(value)); writer.writeEndElement(); }
From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java
/** * @param xmlNode XML node/*from w ww. jav a 2 s . c om*/ * @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:com.fiorano.openesb.application.DmiObject.java
protected static void writeCDATAElement(XMLStreamWriter writer, String element, String content) throws XMLStreamException { if (!StringUtils.isEmpty(content)) { writer.writeStartElement(element); writer.writeCData(content); writer.writeEndElement();//from w w w .ja v a 2 s . co m } }
From source file:de.shadowhunt.subversion.internal.MergeOperation.java
@Override protected HttpUriRequest createRequest() { final DavTemplateRequest request = new DavTemplateRequest("MERGE", repository); request.addHeader("X-SVN-Options", "release-locks"); final Writer body = new StringBuilderWriter(); try {//from w ww. j av a 2s.c om final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("merge"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeStartElement("source"); writer.writeStartElement("href"); writer.writeCData(repository.getPath() + resource.getValue()); writer.writeEndElement(); // href writer.writeEndElement(); // source writer.writeEmptyElement("no-auto-merge"); writer.writeEmptyElement("no-checkout"); writer.writeStartElement("prop"); writer.writeEmptyElement("checked-in"); writer.writeEmptyElement("version-name"); writer.writeEmptyElement("resourcetype"); writer.writeEmptyElement("creationdate"); writer.writeEmptyElement("creator-displayname"); writer.writeEndElement(); // prop if (!infoSet.isEmpty()) { writer.setPrefix(XmlConstants.SVN_PREFIX, XmlConstants.SVN_NAMESPACE); writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-token-list"); writer.writeNamespace(XmlConstants.SVN_PREFIX, XmlConstants.SVN_NAMESPACE); for (final Info info : infoSet) { final String lockToken = info.getLockToken(); assert (lockToken != null) : "must not be null"; final Resource infoResource = info.getResource(); writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock"); writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-path"); writer.writeCData(infoResource.getValueWithoutLeadingSeparator()); writer.writeEndElement(); // lock-path writer.writeStartElement(XmlConstants.SVN_NAMESPACE, "lock-token"); writer.writeCharacters(lockToken); writer.writeEndElement(); // lock-token writer.writeEndElement(); // lock } writer.writeEndElement(); // lock-token-list } writer.writeEndElement(); // merge writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:de.shadowhunt.subversion.internal.httpv1.CheckoutOperation.java
@Override protected HttpUriRequest createRequest() { final Writer body = new StringBuilderWriter(); try {/*from ww w. j a v a2s . com*/ final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("checkout"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeStartElement("activity-set"); writer.writeStartElement("href"); final URI transactionURI = URIUtils.createURI(repository, transaction); writer.writeCData(transactionURI.toString()); writer.writeEndElement(); // href writer.writeEndElement(); // activity-set writer.writeEmptyElement("apply-to-version"); writer.writeEndElement(); //checkout writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body", e); } final URI uri = URIUtils.createURI(repository, resource); final DavTemplateRequest request = new DavTemplateRequest("CHECKOUT", uri); request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:com.hazelcast.simulator.probes.probes.impl.HdrLatencyDistributionResult.java
@Override public void writeTo(XMLStreamWriter writer) { Histogram tmp = histogram.copy();//from w w w .j a v a 2s. co m int size = tmp.getNeededByteBufferCapacity(); ByteBuffer byteBuffer = ByteBuffer.allocate(size); int bytesWritten = tmp.encodeIntoCompressedByteBuffer(byteBuffer); byteBuffer.rewind(); byteBuffer.limit(bytesWritten); String encodedData = Base64.encodeBase64String(byteBuffer.array()); try { writer.writeStartElement(ProbesResultXmlElements.HDR_LATENCY_DATA.getName()); writer.writeCData(encodedData); writer.writeEndElement(); } catch (XMLStreamException e) { throw new RuntimeException(e); } }
From source file:com.fiorano.openesb.application.aps.ApplicationContext.java
public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException { //Start Application Context writer.writeStartElement("ApplicationContext"); //Write Structure if (!StringUtils.isEmpty(m_structure)) { writer.writeStartElement("Structure"); writer.writeCData(m_structure); writer.writeEndElement();/* w ww. ja va 2 s.co m*/ } //Write Default Instance if (!StringUtils.isEmpty(m_defaultInstance)) { FioranoStackSerializer.writeElement("DefaultInstance", m_defaultInstance, writer); } //Write Root Element if (!StringUtils.isEmpty(m_rootElement)) { FioranoStackSerializer.writeElement("RootElement", m_rootElement, writer); } //Write Root Element Namespace if (!StringUtils.isEmpty(m_rootElementNamespace)) { FioranoStackSerializer.writeElement("RootElementNamespace", m_rootElementNamespace, writer); } //Write Structure Type FioranoStackSerializer.writeElement("StructureType", String.valueOf(m_structureType), writer); //End Application Context writer.writeEndElement(); }
From source file:XmlReaderToWriter.java
public static void write(XMLStreamReader xmlr, XMLStreamWriter writer) throws XMLStreamException { switch (xmlr.getEventType()) { case XMLEvent.START_ELEMENT: final String localName = xmlr.getLocalName(); final String namespaceURI = xmlr.getNamespaceURI(); if (namespaceURI != null && namespaceURI.length() > 0) { final String prefix = xmlr.getPrefix(); if (prefix != null) writer.writeStartElement(prefix, localName, namespaceURI); else/*from ww w . j a v a 2s . c om*/ writer.writeStartElement(namespaceURI, localName); } else { writer.writeStartElement(localName); } for (int i = 0, len = xmlr.getNamespaceCount(); i < len; i++) { writer.writeNamespace(xmlr.getNamespacePrefix(i), xmlr.getNamespaceURI(i)); } for (int i = 0, len = xmlr.getAttributeCount(); i < len; i++) { String attUri = xmlr.getAttributeNamespace(i); if (attUri != null) writer.writeAttribute(attUri, xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); else writer.writeAttribute(xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); } break; case XMLEvent.END_ELEMENT: writer.writeEndElement(); break; case XMLEvent.SPACE: case XMLEvent.CHARACTERS: writer.writeCharacters(xmlr.getTextCharacters(), xmlr.getTextStart(), xmlr.getTextLength()); break; case XMLEvent.PROCESSING_INSTRUCTION: writer.writeProcessingInstruction(xmlr.getPITarget(), xmlr.getPIData()); break; case XMLEvent.CDATA: writer.writeCData(xmlr.getText()); break; case XMLEvent.COMMENT: writer.writeComment(xmlr.getText()); break; case XMLEvent.ENTITY_REFERENCE: writer.writeEntityRef(xmlr.getLocalName()); break; case XMLEvent.START_DOCUMENT: String encoding = xmlr.getCharacterEncodingScheme(); String version = xmlr.getVersion(); if (encoding != null && version != null) writer.writeStartDocument(encoding, version); else if (version != null) writer.writeStartDocument(xmlr.getVersion()); break; case XMLEvent.END_DOCUMENT: writer.writeEndDocument(); break; case XMLEvent.DTD: writer.writeDTD(xmlr.getText()); break; } }