Le coin technique: XML
 

Version française

XML is heralded with good reason as the ASCII code of the future. In fact, it is a langage that allows the description of data structures and then the reprensentation of the data itself. Since everything is coded in ASCII, it is perfectly cross-platform, which is a real blessing.

"La conjugaison espagnole" (Spanish conjugation) is an example of XML use. It is a small application where you can select a Spanish verb and then try to conjugate it. The application then corrects your conjugation. It is also possible to display just the conjugation.

The application uses two XML files. The first one contains the list of verbs. The data structure defines the verb's infinitive, its root, whether it is reflexive or not and its type of conjugation.

<?xml version="1.0" encoding="iso-8859-1"?>
<dictionary>
	<verb reflexive="yes">
		<infinitive>acostarse</infinitive>
		<root>acost</root>
		<termination>regular1</termination>
	</verb>
	<verb reflexive="no">
		<infinitive>beber</infinitive>
		<root>beb</root>
		<termination>regular3</termination>
	</verb>
	<verb reflexive="no">
		...
	</verb>
</dictionary>

The structure of this file is so simple, it could also have been defined with juste attributes instead of elements:

<?xml version="1.0" encoding="iso-8859-1"?>
<dictionary>
	<verb reflexive="yes" infinitive="acostarse" root="acost" termination="regular1" />
	<verb reflexive="no" infinitive="beber" root="beb" termination="regular3" />
	<verb ... />
</dictionary>

The second file contains the possible conjugations, for all possible tenses (right now it only contains present indicative, since I am just beginning in Spanish). The file looks like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<terminations>
	<conjugation name="regular1">
		<tense name="presente de indicativo">
			<single1>o</single1>
			<single2>as</single2>
			<single3>a</single3>
			<plural1>amos</plural1>
			<plural2>áis</plural2>
			<plural3>an</plural3>
		</tense>
	</conjugation>
	<conjugation name="regular2">
		...
	</conjugation>
</terminations>

Both files are read unsing the built-in PHP functions. In the first page, I only catch events related to the <verb> elements and display these as a drop-down list. The conjugation test is more complex: first of all, the information related to the verb chosen on the first must be retrieved. Knowing which conjugation it uses, I then extract the conjugation details and display all tenses on the page. The terminations are replace by text input fields, so that the user can enter his guesses. When the "Test" button is pressed, the page reloads itself, goes through the same process as described above, but this time, for the tense that was being tested, the answers entered by the user are displayed. They are compared with the conjugation. Correcte answers are displayed in green, wrong answers in red, with the correction ending between brackets.

The page that just displays the conjugation works in a similair way, but without an input mask.