Altova MapForce 2023 Basic Edition

Wildcards: xs:any/xs:anyAttribute

Home Prev Top Next

This topic explains how to deal with wildcards in mappings. The wildcards xs:any and xs:anyAttribute allow you to use any elements/attributes defined in your schema file. For more information about wildcards, see the W3C Specification.  

 

Wildcards in schema definition

The screenshot below shows that an xs:any element has been defined as a child element of the Person element (Schema view in Altova XMLSpy).

any

Wildcards in MapForce

When a wildcard is defined for an element and/or attribute, this wildcard node will have a excel1-compicon (Change Selection) button next to it (see screenshot below).

anyInMapforce

Wildcard selection

Now our goal is to add another element as a separate node. Click the excel1-compicon button to see the list of elements that you can add to the tree. Note that only elements and attributes that are globally declared in your schema can be seen in the Wildcard selections dialog box (see screenshot below).

anyGlobelements

For our example, we have selected Department. Note that wildcard elements and attributes are inserted after the node with the excel1-compicon button. Now our component looks as follows:

anyFromLocal

You can now map to/from these nodes as usual. In a component, wildcard elements and attributes are marked with (xs:any) and (xs:anyAttribute), respectively (see screenshot above).

 

Remove wildcards

To remove a wildcard node, click the excel1-compicon button and clear the corresponding check box in the Wildcard selections dialog box.

 

Elements/attributes from a different schema

The Wildcard selections dialog box (see above) allows you to use elements/attributes from a different schema. Clicking the Import a different schema button will give you the following options: (i) importing a schema file and (ii) generating a wrapper schema (see description below).

 

Import schema

The Import schema option imports the external schema into the current schema assigned to the component. Note that this option overrides the existing schema on the disk. If the current schema is a remote schema that has been opened from a URL (see Adding Components from a URL) and not from the disk, the schema cannot be modified. In this case, use the Generate wrapper schema option.

 

Generate wrapper schema

The Generate wrapper schema option creates a new schema file called wrapper schema. The advantage of using this option is that the existing schema of the component is not modified. Instead, a new schema will be created which will include both the existing schema and the imported schema. When you select this option, you are prompted to choose where the wrapper schema should be saved. By default, the wrapper schema has the following format: somefile-wrapper.xsd.

 

After you save the wrapper schema, it is by default automatically assigned to the component. MapForce will also ask you whether you want to adjust the schema location so that you can reference the previous main schema. Click Yes to revert to the previous schema; otherwise, click No to have the newly created wrapper schema assigned to the component.

 

Wildcards vs. dynamic node names

There are situations in which elements and/or attributes in an instance are too many to be declared in the schema. Consider the following sample file:

 

<?xml version="1.0" encoding="UTF-8"?>
<message>
  <line1>1</line1>
  <line2>2</line2>
  <line3>3</line3>
  ................
  <line999></line999>  
</message>

 

For such situations, it is recommended to use dynamic node names instead of wildcards. For more information, see Mapping Node Names.

 

© 2017-2023 Altova GmbH