Altova MapForce 2022 Basic Edition

By default, when a mapping produces XML output, the namespace (or set of namespaces) of each element and attribute is automatically derived by MapForce from the schema associated with the target component. This is the default behavior in MapForce and is suitable for most mapping scenarios that involve generation of XML output.


However, there might be cases when you want to have more control over namespaces of elements in the resulting XML output. For example, you may want to manually declare the namespace of an element directly from the mapping.


To understand how this works, open the BooksToLibrary.mfd mapping available in the <Documents>\Altova\MapForce2022\MapForceExamples\Tutorial\. Right-click the library node, and select Add Namespace from the context menu.


Notice that two new nodes are now available under the library node: a namespace and a prefix.


You can now map to them string values from the mapping. In the image below, two constants were defined (from Insert | Constant menu command) that provide the namespace "altova.library" and the prefix "lib":


The result is that, in the generated output, an xmlns:<prefix>="<namespace>" attribute is added to the element, where <prefix> and <namespace> are values that come from the mapping (in this case, from constants). The generated output will now look as follows (notice the highlighted part):


<?xml version="1.0" encoding="UTF-8"?>
<library xmlns:lib="altova.library" xmlns:xsi="" xsi:noNamespaceSchemaLocation="library.xsd">



Note:Declaring custom namespaces (and the Add Namespace command) is meaningful only for target XML components, and applies to elements only. The Add Namespace command is not available for attributes and wildcard nodes. It is also not available for nodes which receive data by means of a Copy-All connection.


You can also declare multiple namespaces for the same element, if necessary. To do this, right-click the node again, and select Add Namespace from the context menu. A new pair of namespace and prefix nodes become available, to which you can connect the new prefix and namespace values.


To remove a previously added namespace declaration, right-click the ns:namespace node, and select Remove Namespace from the context menu.


Both the namespace and prefix input connectors must be mapped, even if you provide empty values to them.


If you want to declare a default namespace (that is, one in the format xmlns="mydefaultnamespace"), map an empty string value to prefix. To see this case in action, edit the example mapping above so as to make the second constant an empty string.


The resulting output would then looks as follows:


<?xml version="1.0" encoding="UTF-8"?>
<library xmlns="altova.library" xmlns:xsi="" xsi:noNamespaceSchemaLocation="library.xsd">



If you need to create prefixes for attribute names, for example <number prod:id="prod557">557</number>, you can achieve this by either enabling dynamic access to node's attributes (see Mapping Node Names), or by editing the schema so that it has a prod:id attribute for <number>.

© 2016-2022 Altova GmbH