Skip to content
  • There are no suggestions because the search field is empty.

Output XML

Example of writing an XML request to an HTTP endpoint.

Prepare an XML payload:

The Intelligence Hub can pass strings across the application.

In the following example, an XML structure is typed up in a Transform as a string using template literal (`).

    // xample XML value
    const exampleXML = `<root_element>
      <levelOneElement>
        <levelTwoElementOne>Value 1</levelTwoElementOne>
        <levelTwoElementTwo>Value 2</levelTwoElementTwo>
        <levelTwoElementThree>
          <levelThreeElementOne>Nested Value 1</levelThreeElementOne>
          <levelThreeElementTwo>Nested Value 2</levelThreeElementTwo>
        </levelTwoElementThree>
      </levelOneElement>
      <levelOneElement>
        <levelTwoElementOne>Value 3</levelTwoElementOne>
        <levelTwoElementTwo>Value 4</levelTwoElementTwo>
        <levelTwoElementFour>Value 5</levelTwoElementFour>
      </levelOneElement>
    </root_element>`;

    // set the value that gets passed to the next Stage
    stage.setValue(exampleXML);

    Configure the output:

    Write New Stage Configuration:

    • Set 'content-type' in the Header:
      • content-type: application/xml
    • Set Body Type to Template. This allows FreeMarker template engine to be applied on the event.value. Here we are using it to remove the outermost double-quotes from the XML string (see REF 1):
    ${value[1..value?length - 2]}

    Considerations:

    • Content-type may need to be set as "text/xml" instead of "application/xml". Refer to your endpoint documentation.
    • Some endpoints may require whitespace characters (space, newline, tab) to be removed from the serialized XML string, in which case a function can be called to carry this out.
    • Leverage the modeling engine with the use of Model/Instances and transforming it to an XML string.
      • If XML namespaces and attributes are needed in the XML elements, these can be coded into the XML string, or added into the FreeMarker Template expression.

    References:

    1. FreeMarker - String Slice