

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 util.xml
<a name="xml-helpers-in-util-xml-js"></a>

 `util.xml`contiene metodi per facilitare la conversione di stringhe XML. 

## elenco di utilità di util.xml
<a name="xml-helpers-in-util-xml-list-js"></a>

 **`util.xml.toMap(String) : Object`**  
Converte una stringa XML in un dizionario.  
**Esempio 1:**  

```
Input:

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

Output (object):

{
    "posts":{
      "post":{
        "id":1,
        "title":"Getting started with GraphQL"
      }
    }
}
```
**Esempio 2:**  

```
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 AppSync</title>
</post>
</posts>

Output (JavaScript object):

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

**`util.xml.toJsonString(String, Boolean?) : 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. È possibile impostare un parametro booleano opzionale per determinare se si desidera codificare il JSON come stringa.