---
sourceDocument: オーストラリア API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/api-reference

 Release :

    - australia

ft:locale :

    - ja-JP

ft:publication_title :

    - オーストラリア API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# XMLUtilJS - グローバル

# XMLUtilJS - グローバル {#ariaid-title1}

* リリースバージョン: Australia
* 
* 更新日 2026年03月12日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：9分

XMLUtilJS スクリプトインクルードは、ディスカバリー スクリプトで使用する JavaScript の XML ユーティリティメソッドを提供します。

このスクリプトインクルードは、 ディスカバリー プラグインで提供されます。このスクリプトインクルードは、XML ユーティリティが必要なサーバーサイド ディスカバリー スクリプトで使用します。

静的変数 XMLUtilJS を使用して、これらのメソッドにアクセスします。

## XMLUtilJS - escapeForXMLText(文字列テキスト) {#ariaid-title2}

指定された文字列のエスケープテキストを提供します。
{#r_XUJ-escapeForXMLText_S__table_upj_wfs_pt__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| テキスト | 文字列 | 書式を設定するテキスト。 |
[表 : 1. パラメーター]

{#r_XUJ-escapeForXMLText_S__table_upj_wfs_pt} {#r_XUJ-escapeForXMLText_S__table_vpj_wfs_pt__entry__2}

| タイプ | 説明 |
|-|-|
| 文字列 | 書式設定されたテキスト。 |
[表 : 2. 返される内容]

{#r_XUJ-escapeForXMLText_S__table_vpj_wfs_pt}  
次の例は、ドキュメント内のエスケープされた XML データをリストする方法を示しています。stringToValue() も参照してください。

    // Create an XML document to work with
    var doc = new XMLDocument2();

    // Add an element called catalog
    var catalog = doc.createElement('catalog');

    // Set current element to the one previously made to add more elements
    doc.setCurrentElement(catalog);

    // Add an element called catalog
    var bookAttribute = doc.createElement('book');

    // Add an attribute to the element created
    bookAttribute.setAttribute('id', 'bk101');

    // Create multiple elements with a defined value
    doc.createElementWithTextValue('author', 'Gambardella, Matthew');
    doc.createElementWithTextValue('title', 'XML Developer');
    doc.createElementWithTextValue('genre', 'Computer');
    doc.createElementWithTextValue('price', '44.95');

    // Pass the created XML document as a string to the XMLUtilJS API function
    var escapedXML = XMLUtilJS.escapeForXMLText(doc.toString());

    // Print the escapedXML. If an invalid XML is created, the original value will be returned
    gs.print(escapedXML);

出力:

    <?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101"/><author>Gambardella, Matthew</author><title>XML Developer</title><genre>Computer</genre><price>44.95</price></catalog>

## XMLUtilJS - stringToValue(文字列 str) {#ariaid-title3}

文字列を XML 値に変換します。
{#r_XUJ-stringToValue_S__table_etz_b3s_pt__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| str | 文字列 | 変換する文字列。 |
[表 : 3. パラメーター]

{#r_XUJ-stringToValue_S__table_etz_b3s_pt} {#r_XUJ-stringToValue_S__table_ftz_b3s_pt__entry__2}

| タイプ | 説明 |
|-|-|
| 文字列 | XML に変換された指定された文字列。 |
[表 : 4. 返される内容]

{#r_XUJ-stringToValue_S__table_ftz_b3s_pt}  
次の例は、エスケープされた XML の文字列をタグ付き XML 出力に変換する方法を示しています。escapeForXMLText() も参照してください。

    //Example of an escaped XML string, previously generated by XMLUtilJS.escapeForXMLText()
    var escapedXML = '<catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer\'s Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book></catalog>';

    //Pass in escaped XML text and store output in a variable
    var output = XMLUtilJS.stringToValue(escapedXML);

    // If the input value is a string value of NULL, the output will be null, otherwise an unescaped XML string value.
    gs.print(output);

出力:

    <catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book></catalog>

## XMLUtilJS - unescapeForXMLText(文字列テキスト) {#ariaid-title4}

指定された文字列のエスケープされていない XML を提供します。
{#r_XUJ-unescapeForXMLText_S__table_in5_pgs_pt__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| テキスト | 文字列 | クリーンアップする XML テキスト。 |
[表 : 5. パラメーター]

{#r_XUJ-unescapeForXMLText_S__table_in5_pgs_pt} {#r_XUJ-unescapeForXMLText_S__table_jn5_pgs_pt__entry__2}

| タイプ | 説明 |
|-|-|
| 文字列 | クリーンアップされた XML 文字列。 |
[表 : 6. 返される内容]

{#r_XUJ-unescapeForXMLText_S__table_jn5_pgs_pt}  
次の例は、エスケープされた XML 文字列をタグ付き XML 出力に変換する方法を示しています。escapeForXMLText() も参照してください。

    //Example of an escaped XML string, previously generated by XMLUtilJS.escapeForXMLText()
    var escapedXML = '<catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer\'s Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book></catalog>';

    //Pass in escaped XML text and store output in a variable
    var output = XMLUtilJS.unescapeForXMLText(escapedXML);


    //Print the escapedXML. If the XML is invalid, the original value will be returned
    gs.print(output);

出力:

    <catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book></catalog>

## XMLUtilJS - valueToString(文字列 XMLvalue) {#ariaid-title5}

XML 値を文字列に変換します。
{#r_XUJ-valueToString_S__table_ix2_4hs_pt__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| XML 値 | 文字列 | 変換する XML |
[表 : 7. パラメーター]

{#r_XUJ-valueToString_S__table_ix2_4hs_pt} {#r_XUJ-valueToString_S__table_jx2_4hs_pt__entry__2}

| タイプ | 説明 |
|-|-|
| 文字列 | 文字列に変換された XML 値。 |
[表 : 8. 返される内容]

{#r_XUJ-valueToString_S__table_jx2_4hs_pt}  
次の例は、XML ドキュメントを文字列に変換する方法を示しています。

    //Create an XML document to work with
    var doc = new XMLDocument2();

    //Add an element called catalog
    var catalog = doc.createElement("catalog");

    //Set our current element to the one previously made to add further elements
    doc.setCurrentElement(catalog);

    //Add an element called catalog
    var bookAttribute = doc.createElement("book");

    //Add an attribute to the element created
    bookAttribute.setAttribute("id" , "bk101");

    //create multiple elements with a defined value
    doc.createElementWithTextValue("author" , "Gambardella, Matthew");
    doc.createElementWithTextValue("title" , "XML Developer");
    doc.createElementWithTextValue("genre" , "Computer");
    doc.createElementWithTextValue("price" , "44.95");

    //Pass the created XML document as a string to the XMLUtilJS API function.
    var escapedXML = XMLUtilJS.valueToString(doc.toString());

    // Print the results
    // Returns NULL if XML is invalid
    gs.print(escapedXML);

出力:

    <?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101"/><author>Gambardella, Matthew</author><title>XML Developer</title><genre>Computer</genre><price>44.95</price></catalog>


