Functions

'map
I

Applies a function to each item in an xml sequence, and returns an xml sequence of the results.

children
I

Returns the children of elements in an xml value.

concat
I

Concatenates xml and string values.

createComment
I

Creates a new xml comment item.

createElement
I

Creates a new xml element item.

createProcessingInstruction
I

Creates a new xml processing instruction item.

createText
I

Constructs an xml value of type Text.

data
I

Returns a string with the character data of an xml value.

elementChildren
I

Selects element children of an xml value.

elements
I

Selects elements from an xml value.

filter
I

Selects the items from an xml sequence for which a function returns true.

forEach
I

Applies a function to each item in an xml sequence.

fromString
I

Constructs an xml value from a string.

get
I

Returns the item of an xml sequence with given index.

getAttributes
I

Returns the map representing the attributes of an xml element.

getChildren
I

Returns the children of an xml element.

getContent
I

Returns the content of a processing instruction or comment item.

getDescendants
I

Returns the descendants of an xml element.

getName
I

Returns a string giving the expanded name of an xml element.

getTarget
I

Returns the target part of the processing instruction.

iterator
I

Returns an iterator over the xml items of an xml sequence.

length
I

Returns number of xml items in an xml value.

setChildren
I

Sets the children of an xml element.

setName
I

Changes the name of an XML element.

slice
I

Returns a subsequence of an xml value.

strip
I

Strips the insignificant parts of the an xml value.

text
I

Selects all the items in a sequence that are of type xml:Text.

'map

function 'map(xml x,  function(ItemType) returns (XmlType) func) returns xml
Isolated Function

Applies a function to each item in an xml sequence, and returns an xml sequence of the results.

Each item is represented as a singleton value.

Parameters

  • x xml
  • the xml value

  • func function(ItemType) returns (XmlType)
  • a function to apply to each child or parameter item

Return Type

(xml)

new xml value containing result of applying function func to each child or parameter item

children

function children(xml x) returns xml
Isolated Function

Returns the children of elements in an xml value.

When parameter x is of type Element, it is equivalent to function getChildren. This is equivalent to elements(x).map(getChildren).

Parameters

  • x xml
  • xml value

Return Type

(xml)

xml sequence containing the children of each element x concatenated in order

concat

function concat((xml | string)... xs) returns xml
Isolated Function

Concatenates xml and string values.

Parameters

  • xs (xml | string)...
  • xml or string items to concatenate

Return Type

(xml)

an xml sequence that is the concatenation of all the parameter xs; an empty xml sequence if the parameter xs is empty

createComment

function createComment(string content) returns Comment
Isolated Function

Creates a new xml comment item.

Parameters

  • content string
  • the content of the comment to be constructed.

Return Type

(Comment)

an xml sequence consisting of a comment with parameter content as the content

createElement

function createElement(string name, xml children) returns Element
Isolated Function

Creates a new xml element item.

Parameters

  • name string
  • the name of the new element

  • children xml (default concat())
  • the children of the new element

Return Type

(Element)

an xml sequence consisting of only a new xml element with parameter name as the name, no attributes, and parameter children as the children

createProcessingInstruction

function createProcessingInstruction(string target, string content) returns ProcessingInstruction
Isolated Function

Creates a new xml processing instruction item.

Parameters

  • target string
  • the target part of the processing instruction to be constructed

  • content string
  • the content part of the processing instruction to be constructed

Return Type

(ProcessingInstruction)

an xml sequence consisting of a processing instruction with parameter target as the target and parameter content as the content

createText

function createText(string data) returns Text
Isolated Function

Constructs an xml value of type Text.

The constructed sequence will be empty when the length of parameter data is zero.

Parameters

  • data string
  • the character data of the Text item

Return Type

(Text)

an xml sequence that is either empty or consists of one text item

data

function data(xml x) returns string
Isolated Function

Returns a string with the character data of an xml value.

The character data of an xml value is as follows:

  • the character data of a text item is a string with one character for each

character information item represented by the text item;

  • the character data of an element item is the character data of its children;
  • the character data of a comment item is the empty string;
  • the character data of a processing instruction item is the empty string;
  • the character data of an empty xml sequence is the empty string;
  • the character data of the concatenation of two xml sequences x1 and x2 is the

concatenation of the character data of x1 and the character data of x2.

Parameters

  • x xml
  • the xml value

Return Type

(string)

a string consisting of all the character data of parameter x

elementChildren

function elementChildren(xml x, string? nm) returns xml
Isolated Function

Selects element children of an xml value.

This is equivalent to children(x).elements(nm).

Parameters

  • x xml
  • the xml value

  • nm string? (default ())
  • the expanded name of the elements to be selected, or () for all elements

Return Type

(xml)

an xml sequence consisting of child elements of elements in parameter x; if parameter nm is (), returns a sequence of all such elements; otherwise, include only elements whose expanded name is parameter nm

elements

function elements(xml x, string? nm) returns xml
Isolated Function

Selects elements from an xml value.

If parameter nm is (), selects all elements; otherwise, selects only elements whose expanded name is parameter nm.

Parameters

  • x xml
  • the xml value

  • nm string? (default ())
  • the expanded name of the elements to be selected, or () for all elements

Return Type

(xml)

an xml sequence consisting of all the element items in parameter x whose expanded name is parameter nm, or, if parameter nm is (), all element items in parameter x

filter

function filter(xml x,  function(ItemType) returns (boolean) func) returns xml
Isolated Function

Selects the items from an xml sequence for which a function returns true.

Each item is represented as a singleton value.

Parameters

  • x xml
  • xml value

  • func function(ItemType) returns (boolean)
  • a predicate to apply to each item to test whether it should be selected

Return Type

(xml)

new xml sequence containing items in parameter x for which function func evaluates to true

forEach

function forEach(xml x,  function(ItemType) returns (() ) func)
Isolated Function

Applies a function to each item in an xml sequence.

Each item is represented as a singleton value.

Parameters

  • x xml
  • the xml value

  • func function(ItemType) returns (() )
  • a function to apply to each item in parameter x

fromString

function fromString(string s) returns xml | error
Isolated Function

Constructs an xml value from a string.

This parses the string using the content production of the XML 1.0 Recommendation.

Parameters

  • s string
  • a string in XML format

Return Type

(xml | error)

xml value resulting from parsing parameter s, or an error

get

function get(xml x, int i) returns xml
Isolated Function

Returns the item of an xml sequence with given index.

This differs from x[i] in that it panics if parameter x does not have an item with index parameter i.

Parameters

  • x xml
  • the xml sequence

  • i int
  • the index

Return Type

(xml)

the item with index parameter i in parameter x

getAttributes

function getAttributes(Element x) returns map<string>
Isolated Function

Returns the map representing the attributes of an xml element.

This includes namespace attributes. The keys in the map are the expanded names of the attributes.

Parameters

Return Type

(map<string>)

attributes of parameter x

getChildren

function getChildren(Element elem) returns xml
Isolated Function

Returns the children of an xml element.

Parameters

Return Type

(xml)

children of parameter elem

getContent

function getContent(ProcessingInstruction | Comment x) returns string
Isolated Function

Returns the content of a processing instruction or comment item.

Parameters

Return Type

(string)

the content of parameter x

getDescendants

function getDescendants(Element elem) returns xml
Isolated Function

Returns the descendants of an xml element.

The descendants of an element are the children of the element together with, for each of those children that is an element, the descendants of that element, ordered so that each element immediately precedes all its descendants. The order of the items in the returned sequence will thus correspond to the order in which the first character of the representation of the item would occur in the representation of the element in XML syntax.

Parameters

Return Type

(xml)

descendants of parameter elem

getName

function getName(Element elem) returns string
Isolated Function

Returns a string giving the expanded name of an xml element.

Parameters

Return Type

(string)

element name

getTarget

function getTarget(ProcessingInstruction x) returns string
Isolated Function

Returns the target part of the processing instruction.

Parameters

Return Type

(string)

target part of parameter x

iterator

function iterator(xml x) returns object {
    public isolated function next() returns record {| ItemType value; |}?;
} 
Isolated Function

Returns an iterator over the xml items of an xml sequence.

Each item is represented by an xml singleton.

Parameters

  • x xml
  • xml sequence to iterate over

Return Type

(object { public isolated function next() returns record {| ItemType value; |}?; } )

iterator object

length

function length(xml x) returns int
Isolated Function

Returns number of xml items in an xml value.

Parameters

Return Type

(int)

number of xml items in parameter x

setChildren

function setChildren(Element elem, xml | string children)
Isolated Function

Sets the children of an xml element.

This panics if it would result in the element structure becoming cyclic.

Parameters

  • children xml | string
  • xml or string to set as children

setName

function setName(Element elem, string xName)
Isolated Function

Changes the name of an XML element.

Parameters

  • xName string
  • new expanded name

slice

function slice(xml x, int startIndex, int endIndex) returns xml
Isolated Function

Returns a subsequence of an xml value.

Parameters

  • x xml
  • the xml value

  • startIndex int
  • start index, inclusive

  • endIndex int (default x.length())
  • end index, exclusive

Return Type

(xml)

a subsequence of parameter x consisting of items with index >= parameter startIndex and < parameter endIndex

strip

function strip(xml x) returns xml
Isolated Function

Strips the insignificant parts of the an xml value.

Comment items, processing instruction items are considered insignificant. After removal of comments and processing instructions, the text is grouped into the biggest possible chunks (i.e., only elements cause division into multiple chunks) and a chunk is considered insignificant if the entire chunk is whitespace.

Parameters

  • x xml
  • the xml value

Return Type

(xml)

x with insignificant parts removed

text

function text(xml x) returns Text
Isolated Function

Selects all the items in a sequence that are of type xml:Text.

Parameters

  • x xml
  • the xml value

Return Type

(Text)

an xml sequence consisting of selected text items