.. _world_xml_parser: World XML files parser ----------------------------- While reading XML tag attributes or XML node values, MVSim XML reader parses the following special expressions: Variables ============ You can define XML-level "variables" and dereference their values later on using the notation ``${var_name}``. Using undefined variables is an error. Example: .. code-block:: xml ... x="${POS_X}" ... .. note:: ```` tags can be defined only as children of the top-level ```` tag at the global scope. Special variables ==================== - ``${MVSIM_CURRENT_FILE_DIRECTORY}`` is resolved to the base directory of the current file being parsed. It is evaluated on the fly as the file is read, so it can be used within included files (see: :ref:`world-includes`) to refer to their physical path. Environment variables ======================== Environment variables can be dereferenced with the notation ``$env{var_name}``. Using undefined variables is an error. A default value can be provided using a pipe separator: ``$env{var_name|default_value}``. If the variable is undefined and a default is supplied, the default is used instead of raising an error. Example: .. code-block:: xml Output of an external program =============================== The ``stdout`` result of an external tool can be invoked like ``$(cmd_to_run arg1 arg2 arg3...)``. Mathematical expressions =============================== Using the notation ``$f{...}``, arbitrary expressions can be evaluated using `MRPT-wrapped version `_ of ``ExprTk``, which provide much more than just mathematical operations, but also ``if`` structures, etc. .. code-block:: xml ... x="$f{POS_X + R*cos(45*M_PI/180)}" ... .. note:: By defining the environment variable ``MVSIM_VERBOSE_PARSE`` to ``1``, you can see all the details about the parser evaluations, useful for debugging. Control flow structures ======================== MVSim XML parser supports programming-like control flow: For loops ^^^^^^^^^ Repeat XML content with an iteration variable: .. code-block:: xml ${i} 0 0 See :ref:`flow control documentation ` for complete details. Conditional inclusion ^^^^^^^^^^^^^^^^^^^^^ Include XML content conditionally: .. code-block:: xml See :ref:`flow control documentation ` for complete details.