Functions - lang.xml

appendChildren

Append children to an XML if its an element type XML. Error otherwise. New children will be appended at the end of the existing children.

concat

Concatenates xml and string values.

copy

Make a deep copy of an XML.

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. This represents each item in the same way as the iterator function.

forEach

Applies a function to each item in an xml sequence. This represents each item in the same way as the iterator function.

fromString

Constructs an xml value from a string. This parses the string using the content production of the XML 1.0 Recommendation.

getAttributes

Returns the map representing the attributes of elem. This includes namespace attributes. The keys in the map are the expanded names of the attributes. Panics if isElement(elem) is not true.

getChildren

Returns the children of elem. Panics if isElement(elem) is not true.

getContent

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

getElementName

Get the fully qualified name of the element as a string. Returns an empty string if the XML is not a singleton.

getItemType

Get the type of a XML as a string. If the XML is singleton, type can be one of 'element', 'text', 'comment' or 'pi'. Returns an empty string if the XML is not a singleton.

getName

Returns a string giving the expanded name of elem.

getTarget

Returns the target part of the processing instruction.

getTextValue

Get the text value of a XML. If the XML is a sequence, concatenation of the text values of the members of the sequence is returned. If the XML is an element, then the text value of the sequence of children is returned. If the XML is a text item, then the text is returned. Otherwise, an empty string is returned.

isComment

Tests whether an xml value is a singleton consisting of only a comment item.

isElement

Tests whether an xml value is a singleton consisting of only an element item.

isEmpty

Check whether the XML sequence is empty.

isProcessingInstruction

Tests whether an xml value is a singleton consisting of only a processing instruction item.

isSingleton

Check whether the XML sequence contains only a single element.

isText

Tests whether an xml sequence consists of zero or more character items.

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. This represents each item in the same way as the iterator function.

removeAttribute

Remove an attribute from an XML.

removeChildren

Remove children matching the given name from an XML. This operation has no effect if the XML is not an element type XML.

select

Get all the items that are of element type, and matches the given qualified name, in an XML sequence.

selectDescendants

Searches in children recursively for elements matching the qualified name and returns a sequence containing them all. Does not search within a matched result.

setAttributes

Sets the attributes to the provided attributes map.

setChildren

Sets the children of elem to children. Panics if isElement(elem) is not true.

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

appendChildren

Append children to an XML if its an element type XML. Error otherwise. New children will be appended at the end of the existing children.

Parameters

  • x xml
  • The xml source

  • children xml
  • children

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

copy

(xml x)

returns xml

Make a deep copy of an XML.

Parameters

  • x xml
  • The xml source

  • Return Type

    (xml)
  • A Copy of the XML

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
  • 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(xml | string) returns (boolean) func)

returns xml

Selects the items from an xml sequence for which a function returns true. This represents each item in the same way as the iterator function.

Parameters

  • x xml
  • xml value

  • func function(xml | string) 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. This represents each item in the same way as the iterator function.

Parameters

  • x xml
  • the xml value

  • func function(xml | string) 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

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. Panics if isElement(elem) is not true.

Parameters

  • Return Type

    (map)
  • attributes of x

getChildren

(Element elem)

returns xml

Returns the children of elem. Panics if isElement(elem) is not true.

Parameters

  • 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

  • Return Type

    (string)
  • the content of x

getElementName

(xml x)

returns string

Get the fully qualified name of the element as a string. Returns an empty string if the XML is not a singleton.

Parameters

  • x xml
  • The xml source

  • Return Type

    (string)
  • Qualified name of the XML as a string

getItemType

(xml x)

returns XMLType

Get the type of a XML as a string. If the XML is singleton, type can be one of 'element', 'text', 'comment' or 'pi'. Returns an empty string if the XML is not a singleton.

Parameters

  • x xml
  • The xml source

  • Return Type

    (XMLType)
  • Type of the XML as a string

getName

(Element elem)

returns string

Returns a string giving the expanded name of elem.

Parameters

  • Return Type

    (string)
  • element name

getTarget

(ProcessingInstruction x)

returns string

Returns the target part of the processing instruction.

Parameters

  • Return Type

    (string)
  • target part of x

getTextValue

(xml x)

returns string

Get the text value of a XML. If the XML is a sequence, concatenation of the text values of the members of the sequence is returned. If the XML is an element, then the text value of the sequence of children is returned. If the XML is a text item, then the text is returned. Otherwise, an empty string is returned.

Parameters

  • x xml
  • The xml source

  • Return Type

    (string)
  • Text value of the xml

isComment

(xml x)

returns boolean

Tests whether an xml value is a singleton consisting of only a comment item.

Parameters

  • x xml
  • xml value

  • Return Type

    (boolean)
  • true if x consists of only a comment item; false other

isElement

(xml x)

returns boolean

Tests whether an xml value is a singleton consisting of only an element item.

Parameters

  • x xml
  • xml value

  • Return Type

    (boolean)
  • true if x consists of only an element item; false otherwise

isEmpty

(xml x)

returns boolean

Check whether the XML sequence is empty.

Parameters

  • x xml
  • The xml source

  • Return Type

    (boolean)
  • Boolean flag indicating whether the XML sequence is empty

isProcessingInstruction

(xml x)

returns boolean

Tests whether an xml value is a singleton consisting of only a processing instruction item.

Parameters

  • x xml
  • xml value

  • Return Type

    (boolean)
  • true if x consists of only a processing instruction item; false otherwise

isSingleton

(xml x)

returns boolean

Check whether the XML sequence contains only a single element.

Parameters

  • x xml
  • The xml source

  • Return Type

    (boolean)
  • Boolean flag indicating whether the XML sequence contains only a single element

isText

(xml x)

returns boolean

Tests whether an xml sequence consists of zero or more character items.

Parameters

  • x xml
  • xml value

  • Return Type

    (boolean)
  • true if x is a sequence containing only character items; false otherwise

iterator

(xml x)

returns $anonType$9

Returns an iterator over the xml items of x

Parameters

  • x xml
  • xml item to iterate

  • Return Type

    ($anonType$9)
  • iterator object A character item is represented by a string of length 1. Other items are represented by xml singletons.

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(xml | string) returns (xml | string) func)

returns xml

Applies a function to each item in an xml sequence, and returns an xml sequence of the results. This represents each item in the same way as the iterator function.

Parameters

  • x xml
  • the xml value

  • func function(xml | string) returns (xml | string)
  • a function to apply to each child or item

  • Return Type

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

removeAttribute

Remove an attribute from an XML.

Parameters

  • x xml
  • The xml source

  • qname string
  • Qualified name of the attribute

removeChildren

Remove children matching the given name from an XML. This operation has no effect if the XML is not an element type XML.

Parameters

  • x xml
  • The xml source

  • qname string
  • Namespace qualified name of the children to be removed

select

(xml x, string qname)

returns xml

Get all the items that are of element type, and matches the given qualified name, in an XML sequence.

Parameters

  • x xml
  • The xml source

  • qname string
  • Qualified name of the element

  • Return Type

    (xml)
  • All the elements-type items in the given XML sequence, that matches the qualified name

selectDescendants

(xml x, string qname)

returns xml

Searches in children recursively for elements matching the qualified name and returns a sequence containing them all. Does not search within a matched result.

Parameters

  • x xml
  • The xml source

  • qname string
  • Qualified name of the element

  • Return Type

    (xml)
  • All the descendants that matches the given qualified name, as a sequence

setAttributes

Sets the attributes to the provided attributes map.

Parameters

  • x xml
  • The xml source

  • attributes map
  • Attributes map

setChildren

Sets the children of elem to children. Panics if isElement(elem) is not true.

Parameters

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

setName

Change the name of element elem to xName.

Parameters

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