

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

# Auxiliares XML em util.xml
<a name="xml-helpers-in-util-xml-js"></a>

 `util.xml` contém métodos para ajudar na conversão de strings XML. 

## Lista de utilitários util.xml
<a name="xml-helpers-in-util-xml-list-js"></a>

 **`util.xml.toMap(String) : Object`**  
Converte uma string XML para um dicionário.  
**Exemplo 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"
      }
    }
}
```
**Exemplo 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 uma string XML para uma string JSON. Isso é semelhante a `toMap`, exceto que a saída é uma string. Isso é útil se quiser converter e retornar diretamente a resposta XML de um objeto HTTP para JSON. Você pode definir um parâmetro booleano opcional para determinar se deseja codificar o JSON em string.