Altova MapForce 2025 Basic Edition

This section describes how MapForce handles NULL values in source and target components. To be able to use the xsi:nil="true" attribute in your XML file, you must specify the nillable="true" attribute for the relevant element(s) in your schema file. To find out more about the nillable and xsi:nil attributes, see the W3C Specification. Note that the xsi:nil attribute is not visible in a component's tree in the Mapping pane.

 

The subsections below describe some of the possible scenarios of mapping NULL values.

 

NULL values in XML components

This subsection discusses some of the possible scenarios of mapping elements with an xsi:nil="true" attribute.

 

Only the source element has xsi:nil="true"/Both source and target elements have xsi:nil="true"

This scenario has the following conditions:

 

The connection is target-driven.

The source element has an xsi:nil="true" attribute. The corresponding target element does not have this attribute.

Alternatively, both source and target elements can have xsi:nil="true" attributes.

The nillable="true" attributes must be set in the source and target schemas.

The source and target element are of simple type.

 

In this case, the target element will have the xsi:nil="true" attribute in the output file, as shown in the sample output file below (highlighted in yellow).

 

<book id="7">

 <author>Edgar Allan Poe</author>

 <title>The Murders in the Rue Morgue</title>

 <category xsi:nil="true"/>

 <year>1841</year>

 <OrderID id="213"/>

</book>

 

Note:If the nillable="true" attribute is not set in the target schema, the corresponding target element will be empty in the output.

 

Only the target element has xsi:nil="true"

This scenario has the following conditions:

 

The connection is target-driven.

The source element does not have an xsi:nil="true" attribute.

The corresponding target element has an xsi:nil="true" attribute.

The source and target elements can be of simple or complex type.

 

In this case, the source element will overwrite the target element containing the xsi:nil="true" attribute. The example below shows a sample output file. The <genre> element includes the xsi:nil="true" attribute in the target element. However, this element has been overwritten at mapping runtime. Therefore, the <genre> element (highlighted in yellow) has Fiction in the output.

 

<publication>

 <id>1</id>

 <author>Mark Twain</author>

 <title>The Adventures of Tom Sawyer</title>

 <genre>Fiction</genre>

 <year>1876</year>

 <OrderID id="124"/>

</publication>

 

Complex-type source element/both complex-type elements have xsi:nil="true"

This scenario has the following conditions:

 

The connection is target-driven.

The source element is of complex type. In our example, the source element has an id="213" attribute and an xsi:nil="true" attribute. The corresponding target element is also of complex type and has an id="124" attribute, but does not have an xsi:nil="true" attribute.

Alternatively, the source and target elements, both of which are of complex type, can have xsi:nil="true" attributes.

 

In this case, the source element will overwrite the target element (highlighted in yellow below). However, the xsi:nil="true" attribute will not be written to the output file automatically. To see the xsi:nil="true" attribute in the target element in the output file, use a copy-all connection.

 

<book id="7">

 <author>Edgar Allan Poe</author>

 <title>The Murders in the Rue Morgue</title>

 <year>1841</year>

 <OrderID id="213"/>

</book>

 

Useful functions

The following functions could help you check, replace, and assign NULL values:

 

is-xsi-nil: Helps to check explicitly whether a source element has a xsi:nil attribute set to true.

substitute-missing: Substitutes a NULL value in the source element with something specific.

set-xsi-nil: Assigns xsi:nil="true" attribute to a target element. This works for target elements of simple and complex types.

substitute-missing-with-xsi-nil: If there is content, it will be written to the target element; if there are any missing values, using this function will result in a target element with a xsi:nil="true" attribute in the output.

Connecting the exists function to a source element with a NULL value returns true even though the element has no content.

 

Note that functions which generate xsi:nil cannot be passed through functions or components which only operate on values (such as the if-else function).

 

© 2018-2024 Altova GmbH