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

Concatenate all the xs. Empty xml sequence if empty.

copy

Make a deep copy of an XML.

createComment

Creates a comment with the specified content.

createElement

Creates an element with the specified children The attributes are empty initially

createProcessingInstruction

Creates a processing instruction with the specified target and content.

elements

Get all the items that are of element type in an XML sequence.

filter

For xml sequence returns a new xml sequence constructed from children of x for which func returns true. For xml element returns a new xml sequence constructed from x if x applied to funct returns true, else returns an empty sequence.

forEach

For xml sequence apply the func to children of item. For xml element apply the func to item.

fromString

This is the inverse of value:toString applied to an xml.

getAttributes

Returns the map representing the attributes of elem. This includes namespace attributes. The keys in the map are the expanded name of the attribute. Panics if isElement(elem) is not true. There is no setAttributes function.

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

Returns true if x is a singleton xml sequence consisting of a comment item.

isElement

Returns true if x is a singleton xml sequence consisting of an element item.

isEmpty

Check whether the XML sequence is empty.

isProcessingInstruction

Returns true if x is a singleton xml sequence consisting of a processing instruction item.

isSingleton

Check whether the XML sequence contains only a single element.

isText

Returns true if x is an xml sequence consisting of one or more character items.

iterator

Returns an iterator over the xml items of x

length

Returns number of XML items in x.

map

For xml sequence returns the result of applying function func to each member of sequence item. For xml element returns the result of applying function funct to item.

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 elmem to xName.

slice

Slice and return a subsequence of the an XML sequence.

strip

Strips any text items from an XML sequence that are all 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

Concatenate all the xs. Empty xml sequence if empty.

Parameters

  • xs xml | string
  • xml or string items to concat

  • Return Type

    (xml)
  • xml sequence containing xs

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

Creates a comment with the specified content.

Parameters

  • content string
  • comment content

  • Return Type

    (Comment)
  • xml comment element

createElement

(string name, xml children)

returns Element

Creates an element with the specified children The attributes are empty initially

Parameters

  • children xml
  • children of element

  • Return Type

    (Element)
  • new xml element

createProcessingInstruction

(string target, string content)

returns ProcessingInstruction

Creates a processing instruction with the specified target and content.

Parameters

  • target string
  • target potion of xml processing instruction

  • content string
  • content potion of xml processing instruction

elements

(xml x)

returns xml

Get all the items that are of element type in an XML sequence.

Parameters

  • x xml
  • The xml source

  • Return Type

    (xml)
  • All the elements-type items in the given XML sequence

filter

(xml x, function(xml | string) returns (boolean) func)

returns xml

For xml sequence returns a new xml sequence constructed from children of x for which func returns true. For xml element returns a new xml sequence constructed from x if x applied to funct returns true, else returns an empty sequence.

Parameters

  • x xml
  • xml value

  • func function(xml | string) returns (boolean)
  • a predicate to apply to each child to determine if it should be included

  • Return Type

    (xml)
  • new xml sequence containing filtered children

forEach

For xml sequence apply the func to children of item. For xml element apply the func to item.

Parameters

  • x xml
  • the xml value

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

fromString

(string s)

returns xml | error

This is the inverse of value:toString applied to an xml.

Parameters

  • s string
  • string representation of xml

  • Return Type

    (xml | error)
  • parsed xml value or 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 name of the attribute. Panics if isElement(elem) is not true. There is no setAttributes function.

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

Returns true if x is a singleton xml sequence consisting of a comment item.

Parameters

  • x xml
  • xml value

  • Return Type

    (boolean)
  • true if x is a xml comment item

isElement

(xml x)

returns boolean

Returns true if x is a singleton xml sequence consisting of an element item.

Parameters

  • x xml
  • xml value

  • Return Type

    (boolean)
  • true if x is an xml element item

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

Returns true if x is a singleton xml sequence consisting of a processing instruction item.

Parameters

  • x xml
  • xml value

  • Return Type

    (boolean)
  • true if x is a xml processing instruction

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

Returns true if x is an xml sequence consisting of one or more character items.

Parameters

  • x xml
  • xml value

  • Return Type

    (boolean)
  • true if x is a sequence containing any charactor items

iterator

(xml x)

returns $anonType$9

Returns an iterator over the xml items of x

Parameters

  • x xml
  • xml item to iterate

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

For xml sequence returns the result of applying function func to each member of sequence item. For xml element returns the result of applying function funct to item.

Parameters

  • 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 elmem to xName.

Parameters

slice

(xml x, int startIndex, int endIndex)

returns xml

Slice and return a subsequence of the an XML sequence.

Parameters

  • x xml
  • The xml source

  • startIndex int
  • Start index, inclusive

  • endIndex int
  • End index, exclusive

  • Return Type

    (xml)
  • Sliced sequence

strip

(xml x)

returns xml

Strips any text items from an XML sequence that are all whitespace.

Parameters

  • x xml
  • The xml source

  • Return Type

    (xml)
  • Striped sequence