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, writeStartElement
public 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
AbstractXMLStreamWriter
getScope().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 URIXMLStreamException
protected void writeStartElementTagEnd() throws XMLStreamException
AbstractXMLStreamWriter
writeStartElementTagEnd
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
XMLStreamException
protected void writeEndElementTag() throws XMLStreamException
AbstractXMLStreamWriter
writeEndElementTag
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
XMLStreamException
public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException
writeAttribute
in interface XMLStreamWriter
writeAttribute
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
XMLStreamException
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException
writeNamespace
in interface XMLStreamWriter
writeNamespace
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
XMLStreamException
protected void writeAttr(String prefix, String localName, String namespaceURI, String value) throws XMLStreamException
AbstractXMLStreamWriter
writeAttr
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 valueXMLStreamException
protected void writeNsDecl(String prefix, String namespaceURI) throws XMLStreamException
AbstractXMLStreamWriter
writeNsDecl
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
prefix
- namespace prefixnamespaceURI
- namespace URIXMLStreamException
protected void writeData(Object data, int type) throws XMLStreamException
AbstractXMLStreamWriter
writeData
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
data
- text/datatype
- one of CHARACTERS, COMMENT, CDATA, DTD, ENTITY_REFERENCE, SPACE
XMLStreamException
public void writeStartDocument(String encoding, String version) throws XMLStreamException
writeStartDocument
in interface XMLStreamWriter
writeStartDocument
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
XMLStreamException
public void writeEndDocument() throws XMLStreamException
writeEndDocument
in interface XMLStreamWriter
writeEndDocument
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
XMLStreamException
public void writeStartArray(String fieldName) throws XMLStreamException
XMLStreamException
public void writeEndArray() throws XMLStreamException
XMLStreamException
public void close() throws XMLStreamException
close
in interface XMLStreamWriter
close
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
XMLStreamException
public void flush() throws XMLStreamException
XMLStreamException
protected void writePI(String target, String data) throws XMLStreamException
AbstractXMLStreamWriter
writePI
in class AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
target
- PI targetdata
- PI data (may be null
)XMLStreamException
public void writeNumber(Number value) throws XMLStreamException
value
- XMLStreamException
public void writeBoolean(Boolean value) throws XMLStreamException
value
- XMLStreamException
Copyright © 2005–2024 Apache Software Foundation. All rights reserved.