public class JsonXMLStreamWriter extends AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
<alice>bob<edgar/></alice>) is not supported.writeDTD(...) and writeEntityRef(...) are not supported.writeCData(...) delegates to writeCharacters(...).writeComment(...) does nothing.writeProcessingInstruction(...) does nothing (except for target xml-multiple, see below).The writer may consume processing instructions
(e.g. <?xml-multiple element-name?>) to properly insert JSON array tokens ('['
and ']'). The client provides this instruction through the
AbstractXMLStreamWriter.writeProcessingInstruction(String, String) method,
passing the (possibly prefixed) field name as data e.g.
...
writer.writeProcessingInstruction("xml-multiple", "item");
for (Item item : items) {
writer.writeStartElement("item");
...
writer.writeEndElement();
}
...
The element name passed as processing instruction data is optional. If omitted, the next element within the current scope will start an array. Note, that this method does not allow to create empty arrays (in fact, the above code sample could create unexpected results, if the name would have been omitted and collection were empty).
| Constructor and Description |
|---|
JsonXMLStreamWriter(JsonStreamTarget target,
boolean repairNamespaces,
boolean multiplePI,
char namespaceSeparator,
boolean namespaceDeclarations)
Create writer instance.
|
JsonXMLStreamWriter(JsonStreamTarget target,
boolean repairNamespaces,
boolean multiplePI,
char namespaceSeparator,
boolean namespaceDeclarations,
boolean xmlNilReadWriteEnabled,
boolean xmlWriteNullForEmptyElement)
Create writer instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
protected void |
writeAttr(String prefix,
String localName,
String namespaceURI,
String value)
Write attribute.
|
void |
writeAttribute(String prefix,
String namespaceURI,
String localName,
String value) |
void |
writeBoolean(Boolean value)
Write boolean value.
|
protected void |
writeData(Object data,
int type)
Write characters/comment/dtd/entity data.
|
void |
writeEndArray() |
void |
writeEndDocument() |
protected void |
writeEndElementTag()
Write end element tag.
|
void |
writeNamespace(String prefix,
String namespaceURI) |
protected void |
writeNsDecl(String prefix,
String namespaceURI)
Write namespace declaration.
|
void |
writeNumber(Number value)
Write number value.
|
protected void |
writePI(String target,
String data)
Read processing instruction.
|
void |
writeStartArray(String fieldName) |
void |
writeStartDocument(String encoding,
String version) |
protected org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo |
writeStartElementTag(String prefix,
String localName,
String namespaceURI)
Write open start element tag.
|
protected void |
writeStartElementTagEnd()
Write close start element tag.
|
getNamespaceContext, getPrefix, getProperty, getScope, isStartDocumentWritten, setDefaultNamespace, setNamespaceContext, setPrefix, writeAttribute, writeAttribute, writeCData, writeCharacters, writeCharacters, writeCharacters, writeComment, writeDefaultNamespace, writeDTD, writeEmptyElement, writeEmptyElement, writeEmptyElement, writeEndElement, writeEntityRef, writeProcessingInstruction, writeProcessingInstruction, writeStartDocument, writeStartDocument, writeStartElement, writeStartElement, writeStartElementpublic JsonXMLStreamWriter(JsonStreamTarget target, boolean repairNamespaces, boolean multiplePI, char namespaceSeparator, boolean namespaceDeclarations)
target - stream targetmultiplePI - whether to consume <xml-multiple?> PIs to trigger array startnamespaceSeparator - namespace prefix separatornamespaceDeclarations - whether to write namespace declarationsrepairNamespaces - repair Namespacespublic JsonXMLStreamWriter(JsonStreamTarget target, boolean repairNamespaces, boolean multiplePI, char namespaceSeparator, boolean namespaceDeclarations, boolean xmlNilReadWriteEnabled, boolean xmlWriteNullForEmptyElement)
target - stream targetmultiplePI - whether to consume <xml-multiple?> PIs to trigger array startnamespaceSeparator - namespace prefix separatornamespaceDeclarations - whether to write namespace declarationsxmlNilReadWriteEnabled - Supports reading and writing of XML Nil elements as defined by http://www.w3.org/TR/xmlschema-1/#xsi_nil when the XML/JSON inputs contains nil/null values.repairNamespaces - repair NamespacesxmlWriteNullForEmptyElement - write null or "" for XML empty elements without nil attributeprotected org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo writeStartElementTag(String prefix, String localName, String namespaceURI) throws XMLStreamException
AbstractXMLStreamWritergetScope().getInfo().writeStartElementTag in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>prefix - element prefix (may be XMLConstants.DEFAULT_NS_PREFIX)localName - local namenamespaceURI - namespace URIXMLStreamExceptionprotected void writeStartElementTagEnd()
throws XMLStreamException
AbstractXMLStreamWriterwriteStartElementTagEnd in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamExceptionprotected void writeEndElementTag()
throws XMLStreamException
AbstractXMLStreamWriterwriteEndElementTag in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamExceptionpublic void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException
writeAttribute in interface XMLStreamWriterwriteAttribute in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamExceptionpublic void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException
writeNamespace in interface XMLStreamWriterwriteNamespace in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamExceptionprotected void writeAttr(String prefix, String localName, String namespaceURI, String value) throws XMLStreamException
AbstractXMLStreamWriterwriteAttr in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>prefix - attribute prefix (may be XMLConstants.DEFAULT_NS_PREFIX)localName - local namenamespaceURI - namespace URIvalue - attribute valueXMLStreamExceptionprotected void writeNsDecl(String prefix, String namespaceURI) throws XMLStreamException
AbstractXMLStreamWriterwriteNsDecl in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>prefix - namespace prefixnamespaceURI - namespace URIXMLStreamExceptionprotected void writeData(Object data, int type) throws XMLStreamException
AbstractXMLStreamWriterwriteData in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>data - text/datatype - one of CHARACTERS, COMMENT, CDATA, DTD, ENTITY_REFERENCE, SPACEXMLStreamExceptionpublic void writeStartDocument(String encoding, String version) throws XMLStreamException
writeStartDocument in interface XMLStreamWriterwriteStartDocument in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamExceptionpublic void writeEndDocument()
throws XMLStreamException
writeEndDocument in interface XMLStreamWriterwriteEndDocument in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamExceptionpublic void writeStartArray(String fieldName) throws XMLStreamException
XMLStreamExceptionpublic void writeEndArray()
throws XMLStreamException
XMLStreamExceptionpublic void close()
throws XMLStreamException
close in interface XMLStreamWriterclose in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamExceptionpublic void flush()
throws XMLStreamException
XMLStreamExceptionprotected void writePI(String target, String data) throws XMLStreamException
AbstractXMLStreamWriterwritePI in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>target - PI targetdata - PI data (may be null)XMLStreamExceptionpublic void writeNumber(Number value) throws XMLStreamException
value - XMLStreamExceptionpublic void writeBoolean(Boolean value) throws XMLStreamException
value - XMLStreamExceptionCopyright © 2005–2019 Apache Software Foundation. All rights reserved.