# 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/creating-structure-from-sample-document).
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/creating-standard-map). ![Standard map creation.](https://help.qlik.com/talend/en-US/data-mapper-user-guide/Resources/images/map_names_and_values_01_map.png)
4. Place a GetElementProperty function on the output elements/key element.
5. Place 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. ![Placement of input level1 element.](https://help.qlik.com/talend/en-US/data-mapper-user-guide/Resources/images/map_names_and_values_02_getelementproperty.png)
6. Place a GetElementProperty function on the output elements/value/key element.
7. Place the input level2 element on the Element argument.
8. Place the input level2 element on the output elements/key/value element.

   Your map is configured, you can now test it. ![Map configuration.](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/mapping-xml-structure-with-dynamic-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/importing-sample-document).
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"
                }
            ]
        }
    ]
}
```