

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

# assistants XML dans \$1util.xml
<a name="xml-helpers-in-utils-xml"></a>

**Note**  
Nous prenons désormais principalement en charge le runtime APPSYNC\$1JS et sa documentation. [Pensez à utiliser le runtime APPSYNC\$1JS et ses guides ici.](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-js-version.html)

`$util.xml`contient des méthodes d'assistance qui peuvent faciliter la traduction des réponses XML en JSON ou en dictionnaire.

## Liste des utilitaires de \$1util.xml
<a name="xml-helpers-in-utils-xml-list"></a>

****`$util.xml.toMap(String) : Map`****  
Convertit une chaîne XML en dictionnaire.  

```
Input:

<?xml version="1.0" encoding="UTF-8"?>
<posts>
<post>
  <id>1</id>
  <title>Getting started with GraphQL</title>
</post>
</posts>

Output (JSON representation):

{
  "posts":{
    "post":{
      "id":1,
      "title":"Getting started with GraphQL"
    }
  }
}


Input:

<?xml version="1.0" encoding="UTF-8"?>
<posts>
<post>
  <id>1</id>
  <title>Getting started with GraphQL</title>
</post>
<post>
  <id>2</id>
  <title>Getting started with AWS AppSync</title>
</post>
</posts>

Output (JSON representation):

{
  "posts":{
    "post":[
        {
          "id":1,
          "title":"Getting started with GraphQL"
        },
        {
          "id":2,
          "title":"Getting started with AWS AppSync"
        }
    ]
  }
}
```

****`$util.xml.toJsonString(String) : String`****  
Convertit une chaîne XML en chaîne JSON. Ceci est similaire à *TomAp*, sauf que la sortie est une chaîne. Cela est utile si vous souhaitez convertir et renvoyer directement la réponse XML à partir d'un objet HTTP vers JSON.

****`$util.xml.toJsonString(String, Boolean) : String`****  
Convertit une chaîne XML en chaîne JSON avec un paramètre booléen facultatif pour déterminer si vous souhaitez coder le JSON par chaîne.