B4J tool works on a grammar definition using an XML Schema subset. In a nutshell, you have to declare all elements first, then all corresponding complex types. Complex types may not be embedded in one another, and have basically attributes and three possible contents:
First, declare all element names that appear in game data, starting with root element quizz.
We don't consider attributes for now.
Each element declaration uses following syntax:
<xsd:element name="elementName" type="seq or ch or st"/>
type attribute is used in XML Schema to reference the corresponding complex type,
e.g. gmr:ElementNameThe "gmr" prefix, associated with your game namespace "http://www.example.com/Guess_Me_Right", is always included in references (for complex types, attributes, etc...).
In this tutorial, we use an intermediate syntax: simply write type="seq" for sequences,
type="ch" for choices, and type="s" for simple content elements (with text content).
Cheat: HERE is corresponding xml schema.
ant addSchemaTypesgenerates template complex types according to your previous declarations. Based on our conventions, each complex type has the same name as corresponding element, different only by first capital letter. THIS is the resulting file.
You should now add attributes declarations, using following syntax:
<xsd:attribute name="attributeName" type="xsd:byte" />Attribute name is free; for an attributeName attribute, an atAttributeName variable will contain decoded value, and an isAtAttributeNamePresent boolean will be available if it is an optional one.
XML Schema | Java |
---|---|
xsd:boolean | boolean |
xsd:byte | byte |
xsd:short | short |
xsd:int | int |
xsd:unsignedInt | int |
xsd:long | long |
xsd:float | int* |
xsd:double | double |
xsd:string | String (UTF-8) |
mathFP:float | int (encoded with MathFP) |
mathFP:radAngle | int (encoded with MathFP) |
mathFP:cosRadAngle | int (encoded with MathFP) |
mathFP:sinRadAngle | int (encoded with MathFP) |
mathFP:minusCosRadAngle | int (encoded with MathFP) |
mathFP:minusSinRadAngle | int (encoded with MathFP) |
include:Id | byte |
include:IdRef | byte |
ignore:Id | None |
ignore:IdRef | None |
Finally, your schema is now VALID! You can use it to validate your game data, using
ant validateDatabut you should first check it is a valid XML Schema subset for B4J using
ant validateSchema
Go on to Chapter 4...
or back
to Chapter 1
or Chapter 2.