Mapping Syntax for xom implementation of datamapper API

To declare a type, a mapping file must be provided and placed in META-INF/services/ and called de.unibi.agai.dapi.xom.XOMPacker$<typename>. It can then be used by calling DAPILoader.findPacker("xml", <typename>).

Mapping Syntax

<?xml version="1.0" encoding="utf-8"?>
<mapper baseTag="MemoryGame">
    <value name="action" type="String">CardSelection/Action/@value</value>
    <value name="timestamp" type="Long" optional="true">TIMESTAMP/*[last()]/@value</value>    
    <value name="task" type="Object" subType="task">STATUS</value>
    <output><![CDATA[<MemoryGame><TIMESTAMP><INSERTED dapi-timestamp:value/></TIMESTAMP>
        dapi-task
<CardSelection><Action dapi-action:value/></CardSelection></MemoryGame>]]></output>
</mapper>

Elements

  • mapper Root element
  • value Define how to extract a value from the input XML document
    • @name the attribute name under which the value should be stored. Must be unique
    • @type the type of the attribute. Supported primitive types are: Byte, Short, Int, Long, Float, Double, Boolean, and String. The value may also be "Object", in which case the sub-type attribute is required.
    • @subType if, and only if, the type is "Object", this specifies a sub-type, for which a mapping definition must also be available, to extract. See the note below, too
    • @optional A boolean value ("true" or "false") which specifies whether the value must always be present ("true") or not.
    • The content of the value tag specifies an XPath expression which determines where to find the value. Its result must be convertible to the specified type.
  • output Template for generating output XML. See below for the syntax

Note When a sub-type is specified, the XPath expression must be given such that that values mapping definition can start working. Usually, this means navigating to the element which contains the sub-type element, not the sub-type's element itself.

Output template syntax

The output template is an XML file, but without the XML header. This facilitates embedding types into one another.

Within the template file, directives of the form dapi-<value>[:attribute] may be used. The value field specified which value to insert. The directive is wholly replaced with the serialization of the value, with the type specified by the preceding value definitions (including sub-types, as in the "dapi-task" example above). It is an error if a name is used which is not defined previously.

The second form ("dapi-value:attribute") also specifies an attribute name, and can be used to generate attributes, e.g. like for the timestamp-value and the action value in the example above.

Note It is possible to generate incorrect XML by using the non-attribute-form of the directive within an element. This is not checked for at the moment. You'll receive an error soon enough, though ;-)