

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# \$1util.xml の XML ヘルパー
<a name="xml-helpers-in-utils-xml"></a>

**注記**  
現在、主に APPSYNC\$1JS ランタイムとそのドキュメントをサポートしています。[こちら](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-js-version.html)にある APPSYNC\$1JS ランタイムとそのガイドの使用をご検討ください。

`$util.xml` には、XML レスポンスを JSON またはディクショナリに変換しやすくするヘルパーメソッドが含まれています。

## \$1util.xml utils リスト
<a name="xml-helpers-in-utils-xml-list"></a>

****`$util.xml.toMap(String) : Map`****  
XML 文字列を辞書に変換します。  

```
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`****  
XML 文字列を JSON 文字列に変換します。これは、出力が文字列である点を除き、*toMap* に似ています。これは、XML レスポンスを HTTP オブジェクトから JSON に直接変換し、返す場合に便利です。

****`$util.xml.toJsonString(String, Boolean) : String`****  
XML 文字列を JSON 文字列に変換します。オプションのブールパラメータを使用して、JSON を文字列エンコードするか判断します。