Soap.Encoder (Soap v2.0.0)

View Source

Builds the XML for a request, using the schema to order and qualify its elements.

Params

Params can be a map, a keyword list, or a list of {name, value} or {name, attributes, value} tuples. Names can be atoms or strings, and a prefix on a name is ignored. To name an element outside the schema, use a {namespace, name} key.

%{"Customer" => %{"Name" => "Ann", "Phones" => ["1", "2"]}}

In a map, keys starting with @ are attributes and #text is an element's text. This is the same form responses decode to.

%{"Price" => %{"@currency" => "EUR", "#text" => 10}}

A list value repeats the element, so [] sends none of an element that can repeat, and an empty one otherwise. "" sends an empty element. nil omits the element, or sends xsi:nil when the schema says it's nillable. %Soap.Raw{} is sent as is, and %Soap.Attachment{} is sent by MTOM.

Values go out in the form their schema type needs. Base64 and hex fields take the raw bytes and encode them.

Validation

A value that can't fit its type, or an element the schema doesn't allow, is an error, and nothing gets sent. validate: false turns this off. Missing required elements are allowed, because servers often accept less than their WSDL says.

Summary

Functions

Encodes one operation's request.

Escapes text content.

Functions

encode(service, operation, params, opts \\ [])

@spec encode(Soap.Service.t(), Soap.Service.Operation.t(), term(), keyword()) ::
  {:ok, %{xml: binary(), attachments: [Soap.Attachment.t()]}}
  | {:error, Soap.Error.t()}

Encodes one operation's request.

Returns the XML and any attachments it refers to.

Options

  • :soap_headers - SOAP headers, in the same forms as params.
  • :mtom - send every base64 field as an attachment.
  • :validate - check params against the schema. Defaults to true.

escape_text(text)

Escapes text content.