[jdom-interest] WBXML encoder/decoder

Gartha Brindoid garthabrindoid at yahoo.com
Mon Jun 24 21:47:53 PDT 2002

First, many thanks to both Hallvard and Ken for their quick
and very helpful responses!  :D

If i may, however, I have a couple follow-up questions.  I
guess i feel that I'm in a bit of a bind.  My key problem
(or part of it, at least) is that the WBXML spec
specifies that attribute values may consist of "opaque"
application-specific data, where that data is simply zero
or more bytes of data.

So, while i really like the idea of a stream/reader class,
I guess I'd run the risk of the XML parser misinterpreting
this opaque data as something other than an attribute
value, and simply failing while parsing.

Even worse, the spec also says that an attribute value may
actually consist of zero or more of these blobs of opaque
data, possibly combined with inline strings, references to
predefined strings in a codebook, etc (see the BNF in
section 5.3 or the description of attribute values in
5.8.3).   So it seems that an attribute value is perhaps
better considered a collection of possibly different data
types and not simply a string.

The parsing of this data is actually fairly
straightforward, it's the storage in a JDOM object that I
am rather unsure about.

So, i could start by writing my own SAX parser, and fire
the the standard events, but since an attribute value could
actually be a collection of values, would I then also write
a custom SAXHandler and extend DefaultJDOMFactory to be
able to create my own custom Attribute objects?  Would I
still need to write my own builder then, or could I simply
use JDOM's SAXBuilder (with the proper inputs so it would
use my classes)?

Or (even better), am I just missing something, and
overlooking a much simpler solution?

Many thanks for your help, and patience.  I'm excited about
using JDOM, but am rather embarrassed to be asking all
these very likely obvious and stupid questions.  Again,
many thanks,


--- Hallvard Tratteberg <hal at idi.ntnu.no> wrote:
> Gartha,
> > So, basically i'll be receiving an input stream
> > consisting of WBXML bytes, and i'd like to "inflate"
> > that into a JDOM Document.  Similarly, i'd like to be
> > able to create a JDOM document and then "deflate" it
> > into WBXML.
> There's at least two ways of doing this:
> 1. Make a special stream/reader class. In this case you
> will typically inflate your WBXML stream into a buffer,
> which you then return characters from when the user of
> your stream ask for them, using read. This stream can
> then be given as an argument to any XML parser, the
> inflation will be invisible, something like: new
> XMLParser(new WBXMLInputStream(binaryStream))
> 2. Make a SAX parser, which decodes the WBXML stream
> and then fires the standard startDocument, startElement,
> character, endElement, endDocument methods on a
> ContentHandler, and all the other methods required.
> I don't really know WBXML, but I guess variant 1. would
> be less work and be more general, since a stream
> object can be used to drive any parser, whether it
> is a SAX parser, direct DOM parser or XMLPULL(?). The
> second variant involves writing a lot more code, since
> the SAX API is much larger than the methods a stream
> class must implement, unless you can reuse an existing
> SAX parser.
> Hallvard
--- Ken Rune Helland <kenh at csc.no> wrote:
> [SNIP]
> > Do i create a SAX parser and then do something like
> > "new SAXBuilder(com.foo.bar.WbxmlParser)"?  Or am I
> > responsible for creating the actual builder?  And, on
> > the other end, when i have a JDOM Document, and i want
> > to output it as WBXML bytes, do I create an outputter
> > by extending XMLOutputter?
> > 
> > See?  I'm pretty clueless on where to start.  Thanks
> > heaps for your patience and help!
> > 
> > garthabrindoid
> I have not involved myself much with the builders and
> outputters, but i think the easyest option for building
> JDOM from WBXML is to make your own builder from scracth
> using the metod signatures of SaxBuilder and DomBuilder
> as a guideline for the signature of your builder class.
> For outputting you can make your own outputter from
> scracth or exstend an exsisting one, your call. 
> On the other hand if you make a WBXML -> sax-events and
> sax-events -> WBXML adapters you can use the saxbuilder
> and saxoutputter for JDOM and you can reuse the adapters
> togheter with any destination and source that consumes
> and produces sax-events, for example XSLT prossesors.
> KenR

Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup

More information about the jdom-interest mailing list