

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

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

**Nota**  
Ora supportiamo principalmente il runtime APPSYNC\$1JS e la relativa documentazione. [Prendi in considerazione l'utilizzo del runtime APPSYNC\$1JS e delle relative guide qui.](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-js-version.html)

`$util.xml`contiene metodi di supporto che possono semplificare la traduzione delle risposte XML in JSON o in un dizionario.

## Elenco di utilità \$1util.xml
<a name="xml-helpers-in-utils-xml-list"></a>

****`$util.xml.toMap(String) : Map`****  
Converte una stringa XML in un dizionario.  

```
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`****  
Converte una stringa XML in una stringa JSON. È simile a *toMap*, tranne per il fatto che l'output è una stringa. Questa funzione è utile se si desidera convertire direttamente e restituire la risposta XML da un oggetto HTTP in formato JSON.

****`$util.xml.toJsonString(String, Boolean) : String`****  
Converte una stringa XML in una stringa JSON con un parametro booleano opzionale per determinare se si desidera codificare il JSON come stringa.