What is the use of serialize ()?

This function serializes the supplied input sequence $arg as described in , returning the serialized representation of the sequence as a string.

This function is deterministic, context-independent, and focus-independent.

The value of the first argument $arg acts as the input sequence to the serialization process, which starts with sequence normalization.

The second argument $params, if present, provides serialization parameters. These may be supplied in either of two forms:

  1. As an output:serialization-parameters element, having the format described in . In this case the type of the supplied argument must match the required type element(output:serialization-parameters).

  2. As a map. In this case the type of the supplied argument must match the required type map(*)

The single-argument version of this function has the same effect as the two-argument version called with $params set to an empty sequence. This in turn is the same as the effect of passing an output:serialization-parameters element with no child elements.

The final stage of serialization, that is, encoding, is skipped. If the serializer does not allow this phase to be skipped, then the sequence of octets returned by the serializer is decoded into a string by reversing the character encoding performed in the final stage.

If the second argument is omitted, or is supplied in the form of an output:serialization-parameters element, then the values of any serialization parameters that are not explicitly specified is implementation-defined, and may depend on the context.

If the second argument is supplied as a map, then the option parameter conventions apply. In this case:

  1. Each entry in the map defines one serialization parameter.

  2. The key of the entry is an xs:string value in the cases of parameter names defined in these specifications, or an xs:QName (with non-absent namespace) in the case of implementation-defined serialization parameters.

  3. The required type of each parameter, and its default value, are defined by the following table. The default value is used when the map contains no entry for the parameter in question, and also when an entry is present, with the empty sequence as its value. The table also indicates how the value of the map entry is to be interpreted in cases where further explanation is needed.

ParameterRequired typeInterpretationDefault Value
allow-duplicate-names xs:boolean? true() means "yes", false() means "no" no
byte-order-mark xs:boolean? true() means "yes", false() means "no" no
cdata-section-elements xs:QName* ()
doctype-public xs:string? Zero-length string and () both represent "absent" absent
doctype-system xs:string? Zero-length string and () both represent "absent" absent
encoding xs:string? utf-8
escape-uri-attributes xs:boolean? true() means "yes", false() means "no" yes
html-version xs:decimal? 5
include-content-type xs:boolean? true() means "yes", false() means "no" yes
indent xs:boolean? true() means "yes", false() means "no" no
item-separator xs:string? absent
json-node-output-method union(xs:string, xs:QName)? See Notes 1, 2 xml
media-type xs:string? (a media type suitable for the chosen method)
method union(xs:string, xs:QName)? See Notes 1, 2 xml
normalization-form xs:string? none
omit-xml-declaration xs:boolean? true() means "yes", false() means "no" yes
standalone xs:boolean? true() means "yes", false() means "no", () means "omit" omit
suppress-indentation xs:QName* ()
undeclare-prefixes xs:boolean? true() means "yes", false() means "no" no
use-character-maps map(xs:string, xs:string)? See Note 3 map{}
version xs:string? 1.0

Notes to the table:

  1. The notation union(A, B) is used to represent a union type whose member types are A and B.

  2. If an xs:QName is supplied for the method or json-node-output-method options, then it must have a non-absent namespace URI. This means that system-defined serialization methods such as xml and json are defined as strings, not as xs:QName values.

  3. For the use-character-maps option, the value is a map, whose keys are the characters to be mapped (as xs:string instances), and whose corresponding values are the strings to be substituted for these characters. The option parameter conventions apply recursively to this nested map.

What is serialize in Python?

Serialization refers to the process of converting a data object (e.g., Python objects, Tensorflow models) into a format that allows us to store or transmit the data and then recreate the object when needed using the reverse process of deserialization.

What is serialize in JavaScript?

The process whereby an object or data structure is translated into a format suitable for transfer over a network, or storage (e.g. in an array buffer or file format). In JavaScript, for example, you can serialize an object to a JSON string by calling the function JSON. stringify() .