Example: Passing Parameters to an Expression
Working with Input
This example shows how xmlmath expressions can take input parameters, prior to being evaluated, using the family of <input> tags.
To run this example, pass two string parameters to the evaluator:
$ java -jar dist/xmlmath-1.1-SNAPSHOT.jar foo bar < samples/parameters.xml parameter x: foo parameter y: bar $
Omitting the parameters will cause warnings to be printed to stderr. Parameter "x" will use its default value:
$ java -jar dist/xmlmath-1.1-SNAPSHOT.jar < samples/parameters.xml Warning: no value specified for input parameter "x". Warning: no value specified for input parameter "y". parameter x: default value parameter y: null $
<expression xmlns="http://xmlmath.org/1.0">
<inputString name="x" description="Some input parameter" value="default value"/>
<inputString name="y"/>
<strcat>
<string value="parameter x: "/>
<linkString name="x"/>
<string value="
parameter y: "/>
<linkString name="y"/>
</strcat>
</expression>
|
Input parameters can be read using the <link> tags. This example uses tag <linkString>, which extends <link>. It is used to link to strings only. For each datatype there is a corresponding link-tag. Apart from <linkString> these include: <linkBoolean>, <linkLong>, <linkDouble> and <linkList>.
Input tags can be used only as the first elements in the <expression> root-tag. Their values can be read anywhere in the expression using <link> tags.

