Functions - lang.xml

children
I

Returns the children of elements in an xml value.

concat
I

Concatenates xml and string values.

createComment
I

Constructs an xml sequence consisting of only a comment item.

createElement
I

Constructs an xml sequence consisting of only a new element item.

createProcessingInstruction
I

Constructs an xml sequence consisting of only a processing instruction item.

createText
I

Constructs an xml sequence representing zero of more parsed characters.

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 x with index i.

getAttributes
I

Returns the map representing the attributes of elem.

getChildren
I

Returns the children of elem.

getContent
I

Returns the content of a text or processing instruction or comment item.

getName
I

Returns a string giving the expanded name of elem.

getTarget
I

Returns the target part of the processing instruction.

iterator
I

Returns an iterator over the xml items of x

length
I

Returns number of xml items in x.

map
I

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

setChildren
I

Sets the children of elem to children.

setName
I

Change the name of element elem to xName.

slice
I

Returns a subsequence of an xml value.

strip
I

Strips the insignificant parts of the an xml value.

children

(xml x)

returns xml
Isolated Function

Returns the children of elements in an xml value. When x is of type Element, it is equivalent to getChildren.

Parameters

  • x xml
  • xml value

  • Return Type

    (xml)
  • xml sequence containing the children of each element x concatenated in order This is equivalent to elements(x).map(getChildren).

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 xs; an empty xml sequence if the xs are empty

createComment

(string content)

returns Comment
Isolated Function

Constructs an xml sequence consisting of only a comment item.

Parameters

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

  • Return Type

    (Comment)
  • an xml sequence consisting of a comment with content content

createElement

(string name, xml children)

returns Element
Isolated Function

Constructs an xml sequence consisting of only a new element item.

Parameters

  • name string
  • the name of the new element

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

  • Return Type

    (Element)
  • an xml sequence consisting of only a new xml element with name name, no attributes, and children children

createProcessingInstruction

(string target, string content)

returns ProcessingInstruction
Isolated Function

Constructs an xml sequence consisting of only a 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 target target and content content

createText

(string chars)

returns Text
Isolated Function

Constructs an xml sequence representing zero of more parsed characters.

Parameters

  • chars string
  • the characters

  • Return Type

    (Text)
  • an xml sequence that is either empty or consists of one text item The constructed sequence will be empty when the length of chars is zero.

elementChildren

(xml x, string? nm)

returns xml
Isolated Function

Selects element children of an xml value

Parameters

  • x xml
  • the xml value

  • nm string? (default <string?> ())
  • 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 x; if nm is (), returns a sequence of all such elements; otherwise, include only elements whose expanded name is nm This is equivalent to children(x).elements(nm).

elements

(xml x, string? nm)

returns xml
Isolated Function

Selects elements from an xml value. If nm is (), selects all elements; otherwise, selects only elements whose expanded name is nm.

Parameters

  • x xml
  • the xml value

  • nm string? (default <string?> ())
  • 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 x whose expanded name is nm, or, if nm is (), all element items in x

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 x for which func evaluates to true

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 x

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 s, or an error

get

(xml x, int i)

returns xml
Isolated Function

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

Parameters

  • x xml
  • the xml sequence

  • i int
  • the index

  • Return Type

    (xml)
  • the item with index i in x

getAttributes

(Element x)

returns map<string>
Isolated Function

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

Parameters

  • x Element
  • xml element

  • Return Type

    (map<string>)
  • attributes of x

getChildren

(Element elem)

returns xml
Isolated Function

Returns the children of elem.

Parameters

  • elem Element
  • xml element

  • Return Type

    (xml)
  • children of elem

getContent

(Text | ProcessingInstruction | Comment x)

returns string
Isolated Function

Returns the content of a text or processing instruction or comment item.

Parameters

  • x Text | ProcessingInstruction | Comment
  • xml item

  • Return Type

    (string)
  • the content of x

getName

(Element elem)

returns string
Isolated Function

Returns a string giving the expanded name of elem.

Parameters

  • elem Element
  • xml element

  • Return Type

    (string)
  • element name

getTarget

(ProcessingInstruction x)

returns string
Isolated Function

Returns the target part of the processing instruction.

Parameters

  • x ProcessingInstruction
  • xml processing instruction item

  • Return Type

    (string)
  • target part of x

iterator

(xml x)

returns object { public function next () returns (record {| (xml|string) value; |}?); }
Isolated Function

Returns an iterator over the xml items of x

Parameters

  • x xml
  • xml sequence to iterate over

  • Return Type

    (object { public function next () returns (record {| (xml|string) value; |}?); })
  • iterator object Each item is represented by an xml singleton.

length

(xml x)

returns int
Isolated Function

Returns number of xml items in x.

Parameters

  • x xml
  • xml item

  • Return Type

    (int)
  • number of XML items in x

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 item

  • Return Type

    (xml)
  • new xml value containing result of applying func to each child or item

setChildren

(Element elem, xml | string children)

Isolated Function

Sets the children of elem to children. This panics if it would result in the element structure becoming cyclic.

Parameters

  • elem Element
  • xml element

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

setName

(Element elem, string xName)

Isolated Function

Change the name of element elem to xName.

Parameters

  • elem Element
  • xml element

  • xName string
  • new expanded name

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 <int> x.length(x))
  • end index, exclusive

  • Return Type

    (xml)
  • a subsequence of x consisting of items with index >= startIndex and < endIndex

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