# Mapping elements names and their values

Create a map to extract XML element names and values.

## About this task

In this example, you want to map the previously created XML structure to get a JSON output containing the XML element names and their values in the key and value elements, respectively.

## Procedure

1. Create a JSON file with the following content and save it on your machine:
   ```
   {
      "elements":[
         {
            "key":"",
            "value":[
               {
                  "key":"",
                  "value":""
               }
            ]
         }
      ]
   }
   ```
2. In Talend Data Mapper, create a structure based on your JSON file to use as output in your map.

   For more information, see [Creating a structure from a sample document](https://help.qlik.com/talend/en-US/data-mapper-user-guide/8.0-R2024-04-and-earlier/creating-structure-from-sample-document "Import a document to automatically generate its structure.").
3. Create a standard map and add the XML structure as input and the JSON structure as output.

   For more information, see [Creating a standard map](https://help.qlik.com/talend/en-US/data-mapper-user-guide/8.0-R2024-04-and-earlier/creating-standard-map "Create a new map and add the input and output structures."). ![](https://help.qlik.com/talend/en-US/data-mapper-user-guide/Resources/images/map_names_and_values_01_map.png)
4. Drag and drop a GetElementProperty function on the output elements/key element.
5. Drag and drop the input level1 element on the Element argument.

   This indicates that the value of the key element should be the name of the level1 element. ![](https://help.qlik.com/talend/en-US/data-mapper-user-guide/Resources/images/map_names_and_values_02_getelementproperty.png)
6. Drag and drop a GetElementProperty function on the output elements/value/key element.
7. Drag and drop the input level2 element on the Element argument.
8. Drag and drop the input level2 element on the output elements/value/value element.

   Your map is configured, you can now test it. ![](https://help.qlik.com/talend/en-US/data-mapper-user-guide/Resources/images/map_names_and_values_03_result.png)
9. Import the XML samples provided in [Mapping an XML structure with dynamic elements](https://help.qlik.com/talend/en-US/data-mapper-user-guide/8.0-R2024-04-and-earlier/mapping-xml-structure-with-dynamic-elements "Use the XPath Name property to work with XML files containing different elements.") as sample input documents.

   For more information, see [Importing a sample document](https://help.qlik.com/talend/en-US/data-mapper-user-guide/8.0-R2024-04-and-earlier/importing-sample-document "Import a sample input document to test your map.").
10. Click Test Run to see the result.

## Results

With the first XML sample provided, the JSON output looks like this:

```
{
    "elements": [
        {
            "key": "book",
            "value": [
                {
                    "key": "title",
                    "value": "Pride and Prejudice"
                },
                {
                    "key": "author",
                    "value": "Jane Austen"
                },
                {
                    "key": "isbn",
                    "value": "978-0141439518"
                }
            ]
        },
        {
            "key": "book",
            "value": [
                {
                    "key": "title",
                    "value": "Jane Eyre"
                },
                {
                    "key": "author",
                    "value": "Charlotte Bronte"
                },
                {
                    "key": "isbn",
                    "value": "978-0553211405"
                }
            ]
        }
    ]
}
```

You can switch to the other sample and click Test Run again to get the following result:

```
{
    "elements": [
        {
            "key": "dvd",
            "value": [
                {
                    "key": "title",
                    "value": "Selma"
                },
                {
                    "key": "director",
                    "value": "Ava DuVernay"
                },
                {
                    "key": "released",
                    "value": "2014"
                }
            ]
        },
        {
            "key": "dvd",
            "value": [
                {
                    "key": "title",
                    "value": "The Hurt Locker"
                },
                {
                    "key": "director",
                    "value": "Kathryn Bigelow"
                },
                {
                    "key": "released",
                    "value": "2008"
                }
            ]
        }
    ]
}
```