Introduction
Sybyx includes both WBXML parser and WBXML generator. The generator is low level tool,
which allows programmatically create WBXML streams with calls like startElement, endElement.
WBXML parser implements SAX interface with minor WBXML specific extensions.
Generating WBXML
WBXMLGenerator provides low level interface to generating WBXML streams.
Using it requires understanding of WBXML format. WBXMLGenerator methods correspond to
WBXML grammar described in this document.
The sequence of calls to WBXMLGenerator methods to produce WBXML document is similar to
the sequence of events that one would expect to get from WBXMLParser during parsing. It starts with a call to
startDocument#. Numbers in the end of methods designate alternative where the grammar allows for multiple alternatives.
For instance WBXML grammar allows to specify the document public identifier with either an integer or a string. The string is
represented with an index into string table. Therefore WBXMLGenerator provides two startDocument methods for each of these alternatives.
Similar to this there are other groups of alternative methods derived from the grammar. Those methods have self-explanatory parameters
that outline the specifics of each alternative.
Sybyx uses WellknownResolver::Token type for WBXML binary tokens. WellknownResolver interface is responsible for conversion of binary tokens into human readable strings during parsing. During WBXML generation application provides concrete binary values
for these tokens. The values for tokens must be greater than 4 and less than 63 (0x3f).
WBXMLGenerator does not specify particular output mechanism for WBXML data.
Rather it uses protected pure virtual functions:
- virtual void outputVersion(const void* data, size_t length) = 0;
- virtual void outputPublicId(const void* data, size_t length) = 0;
- virtual void outputCharset(const void* data, size_t length) = 0;
- virtual void outputStringTable(const void* data, size_t length) = 0;
- virtual void outputBody(const void* data, size_t length) = 0;
These functions should be overloaded in applications.
Parsing WBXML
Sybyx provides two ways of parsing: pull parsing where parser automatically pulls data
from incoming stream and push parser where application reads incoming stream and pushes
chunks of data into parser. Both types of parsing are implemented by the same object WBXMLParser.
In addition to standard SAX objects and interfaces Sybyx uses WBXML specific interfaces.
These interfaces are WellknownResolver for resolving binary codes into XML tags and ExtensionHandler for
handling events caused by WBXML extension objects. For application programmer convenience these
two interfaces are inherited in a single WBXMLHandlerBase object which provides (meaningless) default behavior.
WellknownResolver methods should be overloaded in applications for proper parsing.
Please consult source code and examples for more details