If you are reading this tutorial, then you already have rewritten the manipulative
into the OOP format.
At this point, you should have already identified all parameters needed to call the constructor
of your manipulative class. The purpose of an MPXML file is to store parameters so that their
values can be modified at anytime and the manipulative's behavior will change accordingly.
MPXML's root element is <manip_params>. Inside, it can only contain one
distinct element: <param>. It is important to note that order matters! That
is, if your constructor call is CircleObj(radius, color), then the <param>
element for radius must come before the <param> element for color. We will use
the CircleObj example throughout the tutorial.
-
Create a new file, and name it default.ClassName.mpxml (replace ClassName with the actual
class name -in our case, default.CircleObj.mpxml). You may want to use the MPXML
template as shown below:
<manip_params>
<param type="double"> <name> <canonical>radius</canonical> <contextual>Radius of Circle</contextual> </name> <value>5.3</value> </param>
<param type="string"> <name> <canonical>color</canonical> <contextual>Color of Circle</contextual> </name> <value>orange</value> </param>
</manip_params>
|
-
Each parameter is denoted by a <param> element. The type attribute is
mandatory. The values are: bool, boolean, int, integer, char, string, double, and array.
Every <param> gets two inner elements, <name> and (<value> or <value_select>).
-
The <name> element identifies the parameter on two levels.
<canonical> is the variable name. This must match up with your code.
<contextual> is the meaning of this parameter in context (a short description).
-
The other parameter element is the value (UNLESS you chose array for type. Array types are
discuseed next). There are two ways to describe value.
First is <value>, which is assigned to the parameter variable, and allows users
to change this value to whatever they want.
Second is <value_select>, which operates much like <select> in XHTML.
<value_select> does not allow users to freely set parameter values, only
through selections from a list. Below will provide parameters equivalent to the above definition,
except that the colors can only be chosen from the specified list of orange, blue, and yellow.
<manip_params>
<param type="double"> <name> <canonical>radius</canonical> <contextual>Radius of Circle</contextual> </name> <value>5.3</value> </param>
<param type="string"> <name> <canonical>color</canonical> <contextual>Color of Circle</contextual> </name> <value_select> <option value="orange" selected="true">orange</option> <option value="blue">blue</option> <option value="yellow">yellow</option> </value_select> </param>
</manip_params>
|
-
If the type of your parameter is an array, things are a little different. Treat the
<name> as the same as above, but instead of <value>,
the other inner element is <items>. Items contain a list of <pair>
elements, that is, key-and-value pairs, just like in indexed or associative arrays.
The <pair> elements contain <key> (which is the key/index) and
<param>, which is a recursive definition, allowing the array to hold
any type, including more arrays.
<manip_params>
<param type="double"> <name> <canonical>radius</canonical> <contextual>Radius of Circle</contextual> </name> <value>5.3</value> </param>
<param type="array"> <name> <canonical>color</canonical> <contextual>Color of Circle</contextual> </name> <items> <pair> <key> <value>0</value> </key> <param type="string"> <name> <contextual>Orange color</contextual> </name> <value>orange</value> </param> </pair>
<pair> <key> <value>1</value> </key> <param type="string"> <name> <contextual>Blue color</contextual> </name> <value>blue</value> </param> </pair>
<pair> <key> <value>2</value> </key> <param type="string"> <name> <contextual>Yellow color</contextual> </name> <value>yellow</value> </param> </pair>
</items> </manip_params>
|
A few notes for the above example. Notice that because we modified the second parameter
to be an array type, we would have to overload our Class constructor to take an
array for its second parameter as well. Also notice that <param> elements
within <pair> elements do not need canonical names. This is because they
are already identified by the parent <param> canonical name and its key.
One last thing: the keys themselves do not necessarily have to be 0...N. They can
also be strings. That is, MPXML supports associative arrays.
The second argument above is the JavaScript equivalent of: color = { "orange", "blue", "yellow" };
-
Click here to find the MPXML DTD.
Back to Topics