XML Data Encoding / Decoding Tool for Java MIDP/DOJA (2004–2005)
In the early days of Java applications on mobile phones, memory and storage were counted in mere KB, not in MB. Connectivity was limited and downloads of the code and data of the application were metered on expensive data plans.
Even the most simple games typically require a large amount of data to represent each level, in a format which varies depending on the nature of the game. This data can be conveniently represented in XML, and created by level designers using custom level editors on a computer.
In order to embed that data in the game, it needs to be compressed, typically encoded in a binary format and decoded using a custom decoder, which has to be written for each new game. This is tedious prone to error.
The Binary for Java tool streamlines the creation of custom encoders and decoders for XML data, using an XML Schema annotated with semantic actions written in Java. The generated decoder compresses the data into a compact binary format while the generated decoders extracts that data and provides it as building blocks to the semantic actions to create objects needed by the application, such as game levels.
- Download or checkout a copy of the b4j project
- Check you have Apache Ant and Java JDK 1.4 or higher installed
- Configure user properties at the top of the build.xml
- Bring your own XML document
- Create an empty schema:
ant createEmptySchema
- Edit the schema to list the elements found in your XML document
- Add complex types to the schema:
ant addSchemaTypes
- Edit the schema to add attributes and children in the complex types
- Validate the schema:
ant validateData
- Encode your XML document to binary:
ant encoding
- Test decoding:
ant testDecoding
- Add annotations for semantic actions to the schema:
ant addSemanticActions
- Edit the schema to add your Java code (semantic actions) in annotations
- Generate Java decoder:
ant generateDecoder
- Add it to the Java project for your application
These steps are described in details in the online tutorial,
applied to the example of a quiz game.
They are summarized in a single page job aid:
Quick Start in 5 Steps.
- Chapter 1: Discover the Game
- Chapter 2: Configuring the B4J tool
- Chapter 3: Writing your XML Schema
- Chapter 4: Encoding data
- Chapter 5: Writing your custom decoding code
Some context information about the project,
its partners and technologies
is available in French,
from the presentation at the end of my
Master in Video Games and Interactive Media:
- Project Report for my Master Degree (December 2004)
- Slides for the project presentation (December 2004)
- XSLT Orienté Objets / Object Oriented XSLT (March 2006)
- Author: Eric Bréchemier (October 2004)
- Concept: Fabien Delpiano (May 2004)