Class JsonXMLStreamWriter

  • All Implemented Interfaces:
    XMLStreamWriter

    public class JsonXMLStreamWriter
    extends AbstractXMLStreamWriter<org.apache.synapse.commons.staxon.core.json.JsonXMLStreamWriter.ScopeInfo>
    JSON XML stream writer.

    Limitations

    • Mixed content (e.g. <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).