XMLStreamingAPI - スコープ対象

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:42分
  • 大規模なストリーミング XML ペイロードをビルドし、それを REST または SOAP 要求で使用して大量のデータをサードパーティ API に送信します。非ストリーミングオプション用の XML 文字列としてペイロードを作成することもできます。

    これらのメソッドを ワークフロースタジオ スクリプトステップで sn_ih 名前空間識別子とともに使用します。たとえば、この API を使用して ワークフロースタジオ スクリプトステップで XML ペイロードを作成し、戻り値を REST ステップに渡して、要求をサードパーティサービスに送信できます。詳細については、「ワークフロースタジオ スクリプトステップ」を参照してください。
    注:
    この API は ワークフロースタジオ 環境内でのみ使用できます。

    このクラスにはコンストラクターはありません。代わりに、XMLStreamingBuilder クラスの build() メソッドを呼び出して、XMLStreamingAPI オブジェクトを返す必要があります。

    API 呼び出しの順序

    XML ペイロードを生成するには、まず XMLStreamingBuilder を使用してビルダーオブジェクトをインスタンス化し、 次に XMLStreamingAPI クラスのメソッドを呼び出します。

    1. XMLStreamingBuilder:ビルダーオブジェクトを作成する
    下記のメソッドを次の順番で使用して、ビルダーオブジェクトを作成します。
    1. XMLStreamingBuilder()XMLStreamingBuilder オブジェクトをインスタンス化します。
    2. withAttachment():オプション。添付ファイルとして XML ドキュメントを作成し、ストリーミング添付ファイル [streaming_attachment] テーブルに格納します。このメソッドを呼び出さない場合、API はペイロードを XML 文字列としてビルドします。
    3. expiresAt():オプション。添付ファイルの有効期限が切れる時刻を設定します。デフォルトは false です。withAttachment() メソッドも呼び出す必要があります。
    4. build()XMLStreamingAPI オブジェクトを返します。
    2. XMLStreamingAPI:XML ペイロードをビルドする
    下記のメソッドを次の順番で使用して、XML ペイロードを作成します。
    1. startDocument()XML ドキュメントの最上位の親要素を作成します。
    2. XML ドキュメントに子要素を生成するメソッド:writeTextElement()startElement()writeArray() など。
    3. 要素の属性を生成するメソッド:writeAttribute()writeNamespace()writeDtd() など。
    4. endElement()XML 要素を閉じます。
    5. endDocument最上位の親要素を閉じます。
    6. getXMLString() または getAttachmentId():作成した XML 文字列または添付ファイル ID を返します。
    7. close()XMLStreamingAPI オブジェクトを閉じます。

    サイズ制限

    この API で生成されたペイロードは、これらのサイズ制限を超えることはできません。

    • 添付ファイル:200 MB
    • 文字列:5 MB

    次の例は、XML ドキュメントを作成し、有効期限を定義してストリーミング添付ファイル [streaming_attachment] テーブルに格納する方法を示しています。

    
    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.XMLStreamingBuilder()
        .withAttachment() // Creates the XML document in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the XMLStreamingAPI object.
    
      builder.startDocument("Employee") // Begins generating the XML document.
        .writeTextElement("firstName","John") // Writes a "firstName" element and value.
        .writeTextElement("lastName","Smith")
        .writeTextElement("age","25")
        .startElement("address") // Adds an "address" parent element.
          .writeTextElement("streetAddress", "21 2nd Street") // Writes a child element and value.
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
        .endElement() // Adds a closing tag for the "address" element.
        .startElement("phoneNumber")
          .writeTextElement("type","home")
          .writeTextElement("number","212 555-1234")
          .writeTextElement("type","fax")
          .writeTextElement("number","646 555-4567")
        .endElement()
      .endDocument() // Stops generating the XML document.
          
      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } catch (err) {
      gs.log(err);
    } finally {
      builder.close();
    }

    または、この例では、スクリプトステップで API を使用し、ペイロードを XML 文字列として作成する方法を示します。このオプションを使用して、 5 MB 未満のペイロードを作成できます。

    (function execute(inputs, outputs) {
    
      var builder = new sn_ih.XMLStreamingBuilder().build();
      
      builder.startDocument("Employee")
        .enablePrettyPrint()
        .writeTextElement("firstName","John")
        .writeTextElement("lastName","Smith")
        .writeTextElement("age","25")
        .startElement("address")
          .writeTextElement("streetAddress", "21 2nd Street")
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
        .endElement()
        .startElement("phoneNumber")
          .writeTextElement("type","home")
          .writeTextElement("number","212 555-1234")
          .writeTextElement("type","fax")
          .writeTextElement("number","646 555-4567")
        .endElement()
      .endDocument()
    
      outputs.payload = builder.getXMLString();
      
    })(inputs, outputs);

    出力:

    <?xml version="1.0" encoding="UTF-8"?>
    <firstName>John</firstName>
    <lastName>Smith</lastName>
    <age>25</age>
    <address>
      <streetAddress>21 2nd Street</streetAddress>
      <city>Santa Clara</city>
      <state>CA</state>
      <postalCode>11111</postalCode>
    </address>
    <phoneNumber>
      <type>home</type>
      <number>212 555-1234</number>
      <type>fax</type>
      <number>646 555-4567</number>
    </phoneNumber>

    XMLStreamingAPI - close()

    XMLStreamingAPI オブジェクトを閉じます。XML ドキュメントをビルドした後にストリームを閉じるには、このメソッドを呼び出す必要があります。

    表 : 1. パラメーター
    名前 タイプ 説明
    なし
    表 : 2. 返される内容
    タイプ 説明
    なし

    次の例は、XML ドキュメントを作成し、有効期限を定義してストリーミング添付ファイル [streaming_attachment] テーブルに格納する方法を示しています。

    
    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.XMLStreamingBuilder()
        .withAttachment() // Creates the XML document in streaming mode within an attachment.
        .expiresAt(ttl) // Sets an expiration date for the attachment.
        .build(); // Creates the XMLStreamingAPI object.
    
      builder.startDocument("Employee") // Begins generating the XML document.
        .writeTextElement("firstName","John") // Writes a "firstName" element and value.
        .writeTextElement("lastName","Smith")
        .writeTextElement("age","25")
        .startElement("address") // Adds an "address" parent element.
          .writeTextElement("streetAddress", "21 2nd Street") // Writes a child element and value.
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
        .endElement() // Adds a closing tag for the "address" element.
        .startElement("phoneNumber")
          .writeTextElement("type","home")
          .writeTextElement("number","212 555-1234")
          .writeTextElement("type","fax")
          .writeTextElement("number","646 555-4567")
        .endElement()
      .endDocument() // Stops generating the XML document.
          
      gs.log(builder.getAttachmentId()); // Returns the sys_id of the attachment.
    } catch (err) {
      gs.log(err);
    } finally {
      builder.close();
    }

    XMLStreamingAPI - disablePrettyPrint()

    きれいな印刷 XML 書式設定を終了します。

    このメソッドを呼び出す前に、まず enablePrettyPrint() を呼び出して XML 書式設定をセクションに追加する必要があります。

    表 : 3. パラメーター
    名前 タイプ 説明
    なし
    表 : 4. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、 address 要素にきれいな印刷書式を追加する方法を示しています。

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.XMLStreamingBuilder()
        .withAttachment()
        .expiresAt(ttl)
        .build();
    
      builder.startDocument("Employee")
        .writeTextElement("firstName","John")
        .writeTextElement("lastName","Smith")
        .writeTextElement("age","25")
        .enablePrettyPrint()
        .startElement("address")
          .writeTextElement("streetAddress", "21 2nd Street")
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
        .endElement()
        .disablePrettyPrint()
        .startElement("phoneNumber")
          .writeTextElement("type","home")
          .writeTextElement("number","212 555-1234")
          .writeTextElement("type","fax")
          .writeTextElement("number","646 555-4567")
        .endElement()
      .endDocument()
          
      gs.log(builder.getAttachmentId());
    } catch (err) {
      gs.log(err);
    } finally {
      builder.close();
    }

    XMLStreamingAPI - enablePrettyPrint()

    XML 要素または要素のツリーにきれいな印刷書式を追加します。

    disablePrettyPrint() メソッドを使用して書式設定を終了します。

    表 : 5. パラメーター
    名前 タイプ 説明
    なし
    表 : 6. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、 address 要素にきれいな印刷書式を追加する方法を示しています。

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.XMLStreamingBuilder()
        .withAttachment()
        .expiresAt(ttl)
        .build();
    
      builder.startDocument("Employee")
        .writeTextElement("firstName","John")
        .writeTextElement("lastName","Smith")
        .writeTextElement("age","25")
        .enablePrettyPrint()
        .startElement("address")
          .writeTextElement("streetAddress", "21 2nd Street")
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
        .endElement()
        .disablePrettyPrint()
        .startElement("phoneNumber")
          .writeTextElement("type","home")
          .writeTextElement("number","212 555-1234")
          .writeTextElement("type","fax")
          .writeTextElement("number","646 555-4567")
        .endElement()
      .endDocument()
          
      gs.log(builder.getAttachmentId());
    } catch (err) {
      gs.log(err);
    } finally {
      builder.close();
    }

    XMLStreamingAPI - endDocument()

    XML ドキュメントの構造を終了します。

    startDocument() メソッドを呼び出してストリーミング XML ドキュメントを整理した後、ドキュメントの構造の最後にある endDocument() メソッドを呼び出します。ストリーミング XML ドキュメントの構造を正常にビルドするには、これら 2 つの方法を一緒に使用する必要があります。

    表 : 7. パラメーター
    名前 タイプ 説明
    なし
    表 : 8. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、ユーザーに関する要素を含む XML ドキュメントを作成する方法を示しています。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('Employee')
            .writeTextElement('firstName', 'John')
            .writeTextElement('lastName', 'Smith')
            .writeTextElement('age', '25')
            .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }

    XMLStreamingAPI - endElement()

    終了タグを XML 要素に追加します。

    有効な XML 要素を作成するには、次のメソッドをこの順序で使用します。
    1. startElement() メソッドを使用して開始タグを追加します。
    2. endElement() メソッドを使用して終了タグを追加します。
    表 : 9. パラメーター
    名前 タイプ 説明
    なし
    表 : 10. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、 address という名前の親要素を構築してから、4 つの子要素を記述する方法を示しています。

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.XMLStreamingBuilder()
        .withAttachment()
        .expiresAt(ttl)
        .build();
    
      builder.startDocument("Employee")
          .startElement("address")
          .writeTextElement("streetAddress", "21 2nd Street")
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
        .endElement()
      .endDocument()
          
      gs.log(builder.getAttachmentId());
    } catch (err) {
      gs.log(err);
    } finally {
      builder.close();
    }

    XMLStreamingAPI - getXMLString()

    XML ドキュメントを文字列として返します。

    XML ドキュメントを文字列として返すには、XMLStreamingBuilder クラスの getAttachementId() メソッドを呼び出さないでください。詳細については、「 XMLStreamingBuilder - スコープ付き」を参照してください。

    表 : 11. パラメーター
    名前 タイプ 説明
    なし
    表 : 12. 返される内容
    タイプ 説明
    文字列 XMLStreamingAPI メソッドを使用して文字列として作成された XML ドキュメント。

    次の例は、XML ドキュメントを作成してから、それを文字列として返す方法を示しています。

    (function execute(inputs, outputs) {
    
      var builder = new sn_ih.XMLStreamingBuilder().build();
      
      builder.startDocument("Employee")
        .enablePrettyPrint()
        .writeTextElement("firstName","John")
        .writeTextElement("lastName","Smith")
        .writeTextElement("age","25")
        .startElement("address")
          .writeTextElement("streetAddress", "21 2nd Street")
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
        .endElement()
        .startElement("phoneNumber")
          .writeTextElement("type","home")
          .writeTextElement("number","212 555-1234")
          .writeTextElement("type","fax")
          .writeTextElement("number","646 555-4567")
        .endElement()
      .endDocument()
    
      outputs.payload = builder.getXMLString();
      
    })(inputs, outputs);

    出力:

    <?xml version="1.0" encoding="UTF-8"?>
    <firstName>John</firstName>
    <lastName>Smith</lastName>
    <age>25</age>
    <address>
      <streetAddress>21 2nd Street</streetAddress>
      <city>Santa Clara</city>
      <state>CA</state>
      <postalCode>11111</postalCode>
    </address>
    <phoneNumber>
      <type>home</type>
      <number>212 555-1234</number>
      <type>fax</type>
      <number>646 555-4567</number>
    </phoneNumber>

    XMLStreamingAPI - startDocument(文字列 rootElement, オブジェクト namespaceDefinitionMap)

    XML ドキュメントのビルドを開始します。

    build() メソッドを呼び出した後、startDocument() メソッドを呼び出して XML ドキュメントの整理を開始します。また、ドキュメントの構造の最後で endDocument メソッドを呼び出す必要があります。

    表 : 13. パラメーター
    名前 タイプ 説明
    ルート要素 文字列 オプション。XML ドキュメントのルート要素、または最上位の親要素。
    namespaceDefinitionMap オブジェクト オプション。後続の要素リスト内の名前空間のキーと値、およびそれらに関連する値のマップ。例:
    {
    'namespaceOne':'namespaceValue',
    'namespaceTwo':'namespaceValue'
    }
    表 : 14. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、従業員に関する情報を含む要素を含む XML ドキュメントを作成する方法を示しています。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('Employee')
            .writeTextElement('firstName', 'John')
            .writeTextElement('lastName', 'Smith')
            .writeTextElement('age', '25')
            .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }

    XMLStreamingAPI - startElement(文字列名, オブジェクト namespaceMap, オブジェクト attributeMap, 文字列プリフィックス)

    XML 要素の開始タグを追加します。

    有効な XML 要素を作成するには、次のメソッドをこの順序で使用します。
    1. startElement() メソッドを使用して開始タグを追加します。
    2. endElement() メソッドを使用して終了タグを追加します。
    表 : 15. パラメーター
    名前 タイプ 説明
    name 文字列 XML 要素の名前。
    namespaceMap オブジェクト オプション。後続の要素リスト内の名前空間のキーと値、およびそれらに関連する値のマップ。例:
    {
    'namespaceOne':'namespaceValue',
    'namespaceTwo':'namespaceValue'
    }
    属性マップ オブジェクト オプション。属性のキーと値、および後続の要素リスト内の関連する値のマップ。
    prefix 文字列 オプション。XML 要素のプリフィックス。
    表 : 16. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、 address という名前の親要素を構築してから、4 つの子要素を記述する方法を示しています。

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.XMLStreamingBuilder()
        .withAttachment()
        .expiresAt(ttl)
        .build();
    
      builder.startDocument("Employee")
          .startElement("address")
          .writeTextElement("streetAddress", "21 2nd Street")
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
        .endElement()
      .endDocument()
          
      gs.log(builder.getAttachmentId());
    } catch (err) {
      gs.log(err);
    } finally {
      builder.close();
    }

    XMLStreamingAPI - writeArray(文字列 elementName, アレイ data, 文字列 wrappingElement)

    事前定義されたテキストを含むネストされた要素のリストをストリーミング XML ドキュメントに追加します。

    startDocument() メソッドを呼び出した後、writeArray() メソッドを呼び出して、ネストされた要素のブロックをストリーミング XML ドキュメントに追加できます。

    表 : 17. パラメーター
    名前 タイプ 説明
    要素名 文字列 dataアレイにリストされている各文字列に関連付けられた XML 要素の名前。
    データ アレイ wrappingElement内にネストされた各要素にアサインする値のリスト。
    wrappingElement 文字列 elementNameを含む親要素。
    表 : 18. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、 officeLocations という名前の親要素を作成し、5 つの 都市 要素の配列を入れ子にする方法を示しています。

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.XMLStreamingBuilder()
        .withAttachment()
        .expiresAt(ttl)
        .build();
    
      builder.startDocument("Employee")
          .writeArray('city', ['Santa Clara','San Diego','Chicago','Sydney','London'], 'officeLocations')
      .endDocument()
          
      gs.log(builder.getAttachmentId());
    } catch (err) {
      gs.log(err);
    } finally {
      builder.close();
    }

    XMLStreamingAPI - writeAttribute(文字列名, 文字列値)

    XML ドキュメントの要素に属性を追加します。

    startDocument()startElement()、または writeTextElement() メソッドを呼び出した後、writeAttribute() メソッドを呼び出して、関連する XML 要素に属性を追加できます。

    表 : 19. パラメーター
    名前 タイプ 説明
    name 文字列 XML 要素の属性の名前。
    value 文字列 XML 要素の属性の値。
    表 : 20. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    この例では、 idNumber という名前の属性を employee 要素に追加します。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('Employee')
        .writeAttribute('idNumber','12345')
            .writeTextElement('firstName', 'John')
            .writeTextElement('lastName', 'Smith')
            .writeTextElement('age', '25')
        .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }

    XMLStreamingAPI - writeAttributes(オブジェクト attributeMap)

    XML ドキュメントの要素に属性を追加します。

    startDocument()startElement()、または writeTextElement() メソッドを呼び出した後、writeAttributes() メソッドを呼び出して、関連する XML 要素に属性を追加できます。

    表 : 21. パラメーター
    名前 タイプ 説明
    属性マップ オブジェクト XML 要素に関連付ける属性名と値を含むキーと値のマップ。例:
    {
    'attributeOne':'attributeValue',
    'attributeTwo':'attributeValue'
    }
    表 : 22. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    この例では、idNumberofficeLocation、department という名前の属性を employee 要素に追加します。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('Employee')
        .writeAttributes({'idNumber':'12345', 'officeLocation':'San Diego', 'department':'Sales'})
            .writeTextElement('firstName', 'John')
            .writeTextElement('lastName', 'Smith')
            .writeTextElement('age', '25')
        .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }

    XMLStreamingAPI - writeCData(文字列データ)

    XML ドキュメントに CDATA を追加します。

    writeCDataElement() メソッドを呼び出した後、writeCData() メソッドを呼び出して要素内に CDATA を追加できます。

    表 : 23. パラメーター
    名前 タイプ 説明
    データ 文字列 CDATA 要素の CDATA キーワードの後に含める値。
    表 : 24. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    この例では、CDATA 要素 timeWorked に CDATA を追加します。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('Employee')
            .writeTextElement('firstName', 'John')
            .writeTextElement('lastName', 'Smith')
            .writeTextElement('age', '25')
            .writeCDataElement('timeWorked')
            .writeCData('< 2 years')
        .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }

    XMLStreamingAPI - writeCDataElement(文字列名, 文字列データ, オブジェクトプリフィックス)

    XML ドキュメントに CDATA 要素を追加します。

    startDocument() メソッドを呼び出した後、writeCDataElement() メソッドを呼び出して CDATA 要素を XML ドキュメントに追加できます。

    表 : 25. パラメーター
    名前 タイプ 説明
    name 文字列 CDATA 要素の名前。
    データ 文字列 オプション。CDATA 要素を解析するデータのタイプ。
    prefix オブジェクト オプション。CDATA 要素に含まれる子要素と値のマップ。例:
    {
    'prefixOne':'prefixValue',
    'prefixTwo':'prefixValue'
    }
    writeNamespace() を使用して、XML 要素のプリフィックスを名前空間に関連付ける必要があります。
    表 : 26. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    この例では、 address という名前のドキュメントタイプ定義を使用して、XML ドキュメントの内部ドキュメントタイプ定義を定義します。

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.XMLStreamingBuilder()
        .withAttachment()
        .expiresAt(ttl)
        .build();
    
      builder.startDocument("Employee")
      .writeDtd('address')
      .writeCDataElement('home', '#PCDATA', {'streetAddress', 'city', 'state', 'postalCode'})
          .writeTextElement("streetAddress", "21 2nd Street")
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
      .endDocument()
          
      gs.log(builder.getAttachmentId());
    } catch (err) {
      gs.log(err);
    } finally {
      builder.close();
    }

    XMLStreamingAPI - writeCharacters(文字列テキスト)

    XML ドキュメントにテキストを追加します。

    writeCharacters() メソッドを使用して、XML ドキュメントのセクションに文字列データを挿入します。

    表 : 27. パラメーター
    名前 タイプ 説明
    テキスト 文字列 XML ドキュメントのセクションに追加するテキスト。
    表 : 28. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、XML ドキュメントの要素にテキスト値を追加する方法を示しています。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('Employee')
            .startElement('firstName')
            .writeCharacters('John')
            .EndElement()
            .startElement('lastName')
            .writeCharacters('Smith')
            .endElement()
        .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }

    XMLStreamingAPI - writeComment(文字列コメント)

    XML ドキュメントにコメントを追加します。

    startDocument() メソッドを呼び出した後、writeComment() メソッドを呼び出して XML ドキュメントにコメントを追加できます。

    表 : 29. パラメーター
    名前 タイプ 説明
    コメント 文字列 含めるコメントテキスト。
    表 : 30. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、XML ドキュメントにコメントを追加する方法を示しています。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('Employee')
            .writeComment('Element for information related to active employees.')
            .writeTextElement('firstName', 'John')
            .writeTextElement('lastName', 'Smith')
            .writeTextElement('age', '25')
        .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }

    XMLStreamingAPI - writeDtd(文字列 dtd)

    XML ドキュメントにドキュメントタイプ定義を追加します。

    startDocument() メソッドを呼び出した後、writeDtd() メソッドを呼び出して、有効な XML ドキュメントタイプ定義を XML ドキュメントに追加できます。

    表 : 31. パラメーター
    名前 タイプ 説明
    dtd 文字列 有効な XML ドキュメントタイプ定義の名前。
    表 : 32. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    この例では、 address という名前のドキュメントタイプ定義を使用して、XML ドキュメントの内部ドキュメントタイプ定義を定義します。

    try {
      var ttl = new GlideDateTime("2011-01-01 12:00:00");
      var builder = new sn_ih.XMLStreamingBuilder()
        .withAttachment()
        .expiresAt(ttl)
        .build();
    
      builder.startDocument("Employee")
      .writeDtd('address')
      .writeCDataElement('home', '#PCDATA', {'streetAddress', 'city', 'state', 'postalCode'})
          .writeTextElement("streetAddress", "21 2nd Street")
          .writeTextElement("city", "Santa Clara")
          .writeTextElement("state", "CA")
          .writeTextElement("postalCode", "11111")
      .endDocument()
          
      gs.log(builder.getAttachmentId());
    } catch (err) {
      gs.log(err);
    } finally {
      builder.close();
    }

    XMLStreamingAPI - writeNamespace(文字列プリフィックス, 文字列 namespaceURI)

    XML ドキュメントの要素に名前空間を追加します。

    startDocument()startElement()、または writeTextElement() メソッドを呼び出した後、writeNamespace() メソッドを呼び出して、関連する XML 要素に名前空間を追加できます。

    表 : 33. パラメーター
    名前 タイプ 説明
    prefix 文字列 XML 名前空間のプリフィックス。
    namespaceURI 文字列 オプション。名前空間の URI。
    表 : 34. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、名前空間と URI を 会社 ルート要素に追加し、ネストされた companyName 要素にプリフィックスを割り当てる方法を示しています。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('company')
        .writeNamespace('x','https://www.servicenow.com')
            .writeTextElement('companyName', 'ServiceNow')
            .writeNamespace('x')
        .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }

    XMLStreamingAPI - writeNamespaces(オブジェクト namespaceMap)

    XML ドキュメントの root 要素 名前空間を追加します。

    startDocument() メソッドまたは startElement() メソッドを呼び出した後、writeNamespaces() メソッドを呼び出して、関連する XML 要素の名前空間を宣言できます。

    表 : 35. パラメーター
    名前 タイプ 説明
    namespaceMap オブジェクト XML ドキュメントのルート要素に関連付ける名前空間プリフィックスと URI を含むキーと値のマップ。例:
    {
    'namespaceOne':'namespaceValue',
    'namespaceTwo':'namespaceValue'
    }
    表 : 36. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    この例では、 会社 ルート要素に 2 つの名前空間と URI を追加し、入れ子になった要素に適切なプレフィックスを割り当てます。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('company')
        .writeNamespaces({'x':'https://www.servicenow.com', 'y':'https://www.developer.servicenow.com'})
            .writeTextElement('companyName', 'ServiceNow')
            .writeNamespace('x')
            .writeTextElement('devFramework', 'UI Framework')
            .writeNamespace('y')
        .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }

    XMLStreamingAPI - writeTextElement(文字列名, 文字列テキスト, オブジェクトプリフィックス)

    単一の XML 要素を XML ドキュメントに追加します。

    startDocument() メソッドを呼び出した後、writeTextElement() メソッドを呼び出して、単一の XML 要素を XML ドキュメントの構造に追加できます。

    表 : 37. パラメーター
    名前 タイプ 説明
    name 文字列 XML 要素の名前。
    テキスト 文字列 XML 要素の値。
    prefix オブジェクト オプション。XML 要素に関連付けられたプリフィックスと値のマップ。例:
    {
    'prefixOne':'prefixValue',
    'prefixTwo':'prefixValue'
    }
    writeNamespace() を使用して、XML 要素のプリフィックスを名前空間に関連付ける必要があります。
    表 : 38. 返される内容
    タイプ 説明
    XML ストリーミング API ペイロードをビルドするためのストリーミング XML オブジェクト。

    次の例は、従業員に関する情報を含む 3 つの要素を含む XML ドキュメントを作成する方法を示しています。

    try {
        var ttl = new GlideDateTime('2011-01-01 12:00:00');
        var builder = new sn_ih.XMLStreamingBuilder().withAttachment().expiresAt(ttl);
        var streamingDocument = builder.build();
    
        streamingDocument.startDocument('Employee')
            .writeTextElement('firstName', 'John')
            .writeTextElement('lastName', 'Smith')
            .writeTextElement('age', '25')
        .endDocument();
        gs.log(streamingDocument.getAttachmentId());
    } catch (err) {
        gs.log(err);
    } finally {
        streamingDocument.close();
    }