Functions - lang.xml

children
Returns the children of elements in an xml value.
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.
elementChildren
Selects element children of an xml value
elements
Selects 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.

children

(xml x)

returns xml
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
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

elementChildren

(xml x, string? nm)

returns xml
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
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
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

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
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)
  • 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 T7
Returns an iterator over the xml items of x

Parameters

  • x xml
  • xml sequence to iterate over

  • Return Type

    (T7)
  • 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

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

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 <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
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