|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.odysseus.staxon.base.AbstractXMLStreamWriter<de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo>
de.odysseus.staxon.json.JsonXMLStreamWriter
public class JsonXMLStreamWriter
JSON XML stream writer.
<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 Summary | |
|---|---|
JsonXMLStreamWriter(JsonStreamTarget target,
boolean repairNamespaces,
boolean multiplePI,
char namespaceSeparator,
boolean namespaceDeclarations)
Create writer instance. |
|
| Method Summary | |
|---|---|
void |
close()
|
void |
flush()
|
protected void |
writeAttr(String prefix,
String localName,
String namespaceURI,
String value)
Write attribute. |
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. |
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 de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo |
writeStartElementTag(String prefix,
String localName,
String namespaceURI)
Write open start element tag. |
protected void |
writeStartElementTagEnd()
Write close start element tag. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
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 declarations| Method Detail |
|---|
protected de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo writeStartElementTag(String prefix,
String localName,
String namespaceURI)
throws XMLStreamException
AbstractXMLStreamWritergetScope().getInfo().
writeStartElementTag in class AbstractXMLStreamWriter<de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo>prefix - element prefix (may be XMLConstants.DEFAULT_NS_PREFIX)localName - local namenamespaceURI - namespace URI
XMLStreamException
protected void writeStartElementTagEnd()
throws XMLStreamException
AbstractXMLStreamWriter
writeStartElementTagEnd in class AbstractXMLStreamWriter<de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamException
protected void writeEndElementTag()
throws XMLStreamException
AbstractXMLStreamWriter
writeEndElementTag in class AbstractXMLStreamWriter<de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamException
protected void writeAttr(String prefix,
String localName,
String namespaceURI,
String value)
throws XMLStreamException
AbstractXMLStreamWriter
writeAttr in class AbstractXMLStreamWriter<de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo>prefix - attribute prefix (may be XMLConstants.DEFAULT_NS_PREFIX)localName - local namenamespaceURI - namespace URIvalue - attribute value
XMLStreamException
protected void writeNsDecl(String prefix,
String namespaceURI)
throws XMLStreamException
AbstractXMLStreamWriter
writeNsDecl in class AbstractXMLStreamWriter<de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo>prefix - namespace prefixnamespaceURI - namespace URI
XMLStreamException
protected void writeData(Object data,
int type)
throws XMLStreamException
AbstractXMLStreamWriter
writeData in class AbstractXMLStreamWriter<de.odysseus.staxon.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 XMLStreamWriterwriteStartDocument in class AbstractXMLStreamWriter<de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamException
public void writeEndDocument()
throws XMLStreamException
writeEndDocument in interface XMLStreamWriterwriteEndDocument in class AbstractXMLStreamWriter<de.odysseus.staxon.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 XMLStreamWriterclose in class AbstractXMLStreamWriter<de.odysseus.staxon.json.JsonXMLStreamWriter.ScopeInfo>XMLStreamException
public void flush()
throws XMLStreamException
XMLStreamException
protected void writePI(String target,
String data)
throws XMLStreamException
AbstractXMLStreamWriter
writePI in class AbstractXMLStreamWriter<de.odysseus.staxon.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
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||