SOAP_HEADER_TO_OBJECT

The function SOAP_HEADER_TO_OBJECT takes a SOAP envelope in the form of a string and returns its header as an Object in Airscript.

This function takes a string as input. The given string is expected to be parsable as a valid SOAP envelope. It returns the SOAP envelope's header as an Object in Airscript.

This function is also capable of parsing modifiers that define formatting elements with no one-to-one equivalent in Airscript Objects. These modifiers make it possible to use the SOAP_HEADER_TO_OBJECT function to generate Objects that incorporate the information stored in XML elements and attributes such that context is maintained. Modifier details must be specified in a single modifier Object that the SOAP_HEADER_TO_OBJECT function accepts as optional input.

Declaration

SOAP_HEADER_TO_OBJECT(soap, modifier) -> object

Parameters

soap (required, type: string)
A string that represents a valid SOAP envelope.

modifier (optional, type: Object)
An object with one or many of the following properties:

  • ignoreAttributes (optional, type: boolean, default: TRUE) - Defines whether the resulting will exclude XML attributes when generating the equivalent Object.TRUE means that it will, FALSE means that it won't.
  • attributeNamePrefix (optional, type: string, default: "") - Defines the string that will distinguish XML elements from XML attributes when the equivalent Object is generated. Object properties generated by XML elements will have the attributeNamePrefix prefixing their key, while Object properties generated by XML attributes will not.

Return Values

object (type: Object)
The Airscript Object equivalent to the given SOAP envelope's header.

Examples

Assume the following examples has access to the following SOAP envelope, which has been pulled in from an external system and converted into a string designated example_soap:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header header="executive" header_id="1">
    <header>contact</header>
  </soap:Header>
  <soap:Body>
    <contact id="01-0001768">
      <name>Joan Smith</name>
      <title>CEO</title>
    </contact>
  </soap:Body>
</soap:Envelope>

The string example_soap can be given directly as input to the SOAP_HEADER_TO_OBJECT function:

SOAP_HEADER_TO_OBJECT(example_soap) -> { "header": "contact" }

By default, the attributes in the header of the example SOAP envelope are ignored when generating its equivalent Object, but this can be changed by using a modifier Object with an ignoreAttributes property, as follows:

SOAP_HEADER_TO_OBJECT(
  example_soap,
  { "ignoreAttributes": FALSE }
) -> {
  "header": "executive",
  "header_id": "1"
}

The Object generated by the above expression does not differentiate which of its properties were generated from XML elements and which of its properties were generated from XML attributes. The attribute designated header was also overwritten by the element of the same name.

To maintain the contextual difference between the XML elements and attributes while making sure no information is lost, an attributeNamePrefix property can be added to the modifier Object. For instance, in the following example, Object properties generated from XML elements are prefixed with the string "@". Note how this prevents the value stored in an attribute from being overwritten by an element of the same name:

SOAP_HEADER_TO_OBJECT(
  example_soap,
  {
    "ignoreAttributes": FALSE,
    "attributeNamePrefix": "@"
  }
) -> {
  "header": "contact",
  "@header": "executive",
  "@header_id": "1"
}