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 |
'map
function 'map(xml x, function(Element | Comment | ProcessingInstruction | Text) 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(Element | Comment | ProcessingInstruction | Text) returns (XmlType)
a function to apply to each child or item
children
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
concat
Concatenates xml and string values.
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
Creates a new xml comment item.
Parameters
- content string
the content of the comment to be constructed.
createElement
Creates a new xml element item.
Parameters
- name string
the name of the new element
- children xml (default xml``)
the children of the new element
Return Type
(Element)an xml sequence consisting of only a new xml element with name name
,
attributes attributes
, and children children
The element's attribute map is a newly created map, into which any attributes specified
by the attributes
map are copied.
createProcessingInstruction
function createProcessingInstruction(string target, string content) returns ProcessingInstruction
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
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
data
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
elementChildren
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
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(Element | Comment | ProcessingInstruction | Text) 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(Element | Comment | ProcessingInstruction | Text) 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(Element | Comment | ProcessingInstruction | Text) 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(Element | Comment | ProcessingInstruction | Text) returns (() )
a function to apply to each item in parameter x
fromString
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
get
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
.
Return Type
(Element | Comment | ProcessingInstruction | Text)the item with index parameter i
in parameter x
getAttributes
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
- x Element
xml element
getChildren
Returns the children of an xml element.
Parameters
- elem Element
xml element
getContent
function getContent(ProcessingInstruction | Comment x) returns string
Returns the content of a processing instruction or comment item.
Parameters
- x ProcessingInstruction | Comment
xml item
getDescendants
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
- elem Element
xml element
getName
Returns a string giving the expanded name of an xml element.
Parameters
- elem Element
xml element
getTarget
function getTarget(ProcessingInstruction x) returns string
Returns the target part of the processing instruction.
Parameters
- x ProcessingInstruction
xml processing instruction item
iterator
function iterator(xml x) returns object {
public isolated function next() returns record {| ItemType value; |}?;
}
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
setChildren
Sets the children of an xml element.
This panics if it would result in the element structure becoming cyclic.
setName
Changes the name of an XML element.
slice
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
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