Functions - lang.xml

concat

Concatenates xml and string values.

createComment

Constructs an xml sequence consisting of only a comment item.

createElement

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

createProcessingInstruction

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

elements

Selects the elements from an xml value.

filter

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

forEach

Applies a function to each item in an xml sequence.

fromString

Constructs an xml value from a string.

get

Returns the item of x with index i.

getAttributes

Returns the map representing the attributes of elem.

getChildren

Returns the children of elem.

getContent

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

getName

Returns a string giving the expanded name of elem.

getTarget

Returns the target part of the processing instruction.

iterator

Returns an iterator over the xml items of x

length

Returns number of xml items in x.

map

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

setChildren

Sets the children of elem to children.

setName

Change the name of element elem to xName.

slice

Returns a subsequence of an xml value.

strip

Strips the insignificant parts of the an xml value.

concat

(xml | string... xs)

returns xml

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

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

Constructs an xml sequence consisting of only a new 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 name name, no attributes, and children children

createProcessingInstruction

(string target, string content)

returns ProcessingInstruction

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

elements

(xml x)

returns xml

Selects the elements from an xml value.

Parameters

  • x xml
  • the xml value

  • Return Type

    (xml)
  • an xml sequence consisting of all the element items in x

filter

(xml x, function(ItemType) returns (boolean) func)

returns xml

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)

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

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

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>

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

Returns the children of elem.

Parameters

  • elem Element
  • xml element

  • Return Type

    (xml)
  • children of elem

getContent

(Text | ProcessingInstruction | Comment x)

returns string

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

Returns a string giving the expanded name of elem.

Parameters

  • elem Element
  • xml element

  • Return Type

    (string)
  • element name

getTarget

(ProcessingInstruction x)

returns string

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; |}?); }

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

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

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)

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)

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

Returns a subsequence of an xml value.

Parameters

  • x xml
  • the xml value

  • startIndex int
  • start index, inclusive

  • endIndex int (default 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

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