Mapping Node Names

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Designing Mappings >

Mapping Node Names

Most of the time when you create a mapping with MapForce, the goal is to read values from a source and write values to a target. However, there might be cases when you want to access not only the node values from the source, but also the node names. For example, you might want to create a mapping which reads the element or attribute names (not values) from a source XML and converts them to element or attribute values (not names) in a target XML.

 

Consider the following example: you have an XML file that contains a list of products. Each product has the following format:

 

  <product>

    <id>1</id>

    <color>red</color>

    <size>10</size>

  </product>

 

Your goal is to convert information about each product into name-value pairs, for example:

 

  <product>
    <attribute name="id" value="1" />
    <attribute name="color" value="red" />
    <attribute name="size" value="10" />
</product>

 

For such scenarios, you would need access to the node name from the mapping. With dynamic access to node names, which the subject of this topic, you can perform data conversions such as the one above.

 

Note:You can also perform the transformation above by using the node-name and static-node-name core library functions. However, in this case, you need to know exactly what element names you expect from the source, and you need to connect every single such element manually to the target. Also, these functions might not be sufficient, for example, when you need to filter or group nodes by name, or when you need to manipulate the data type of the node from the mapping.

 

Accessing node names dynamically is possible not only when you need to read node names, but also when you need to write them. In a standard mapping, the name of attributes or elements in a target is always known before the mapping runs; it comes from the underlying schema of the component. With dynamic node names, however, you can create new attributes or elements whose name is not known before the mapping runs. Specifically, the name of the attribute or element is supplied by the mapping itself, from any source supported by MapForce.

 

For dynamic access to a node's children elements or attributes to be possible, the node must actually have children elements or attributes, and it must not be the XML root node.

 

Dynamic node names are supported when you map to or from the following component types:

 

XML
CSV/FLF*

 

* Requires MapForce Professional or Enterprise Edition.

 

Dynamic node names are supported in any of the following mapping languages: Built-In*, XSLT2, XQuery*, C#*, C++*, Java*.

 

* Requires MapForce Professional or Enterprise Edition.

 

For information about how dynamic node names work, Getting Access to Node Names. For a step-by-step mapping example, see Example: Map Element Names to Attribute Values.


© 2019 Altova GmbH