Ballerina API Documentation

Functions of ballerina.lang.xmls package

function addAttribute(xml x, string xPath, string name, string value)

Adds an attribute to the XML element that matches the given XPath. If the XPath matches the text value of an existing element, or if the XPath does not match an existing element, this operation will have no effect.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
namestringName of the attribute to be added
valuestringAttribute value

function addAttributeWithNamespace(xml x, string xPath, string name, string value, map namespaces)

Adds an attribute to the XML element that matches the given XPath. If the XPath matches the text value of an existing element, or if the XPath does not match an existing element, this operation will have no effect. Namespaces are supported.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
namestringName of the attribute to be added
valuestringAttribute value
namespacesmapA map object consisting of namespaces

function addElement(xml x, string xPath, xml value)

Adds an XML element to the location that matches the given XPath. If the XPath matches the text value of an existing element, or if the XPath does not match an existing element, this operation will have no effect.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
valuexmlAn XML value

function addElementWithNamespace(xml x, string xPath, xml value, map namespaces)

Adds an XML element to the location that matches the given XPath. If the XPath matches the text value of an existing element, or if the XPath does not match an existing element, this operation will have no effect. Namespaces are supported.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
valuexmlAn XML value
namespacesmapA map object consisting of namespaces

function children(xml x) (xml )

Selects all the children of the elements in an XML, and return as a sequence.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
xmlAll the children of the elements in the xml

function copy(xml x) (xml )

Make a deep copy of an XML.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
xmlA Copy of the XML

function elements(xml x) (xml )

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

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
xmlAll the elements-type items in the given XML sequence

function getElementName(xml x) (string )

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

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
stringxml: Qualified name of the XML as a string

function getItemType(xml x) (string )

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:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
stringxml: Type of the XML as a string

function getString(xml x, string xPath) (string )

Evaluates the XPath on an XML object and returns the matching string value.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath

Return Parameters:

Return VariableData TypeDescription
stringMatching string value

function getStringWithNamespace(xml x, string xPath, map namespaces) (string )

Evaluates the XPath on an XML object and returns the matching string value. Namespaces are supported.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
namespacesmapA map object consisting of namespaces

Return Parameters:

Return VariableData TypeDescription
stringMatching string value

function getTextValue(xml x) (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:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
stringxml: Text value of the xml

function getXml(xml x, string xPath) (xml )

Evaluates the XPath on an XML object and returns the matching XML object.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath

Return Parameters:

Return VariableData TypeDescription
xmlMatching XML object

function getXmlWithNamespace(xml x, string xPath, map namespaces) (xml )

Evaluates the XPath on an XML object and returns the matching XML object. Namespaces are supported

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
namespacesmapA map object consisting of namespaces

Return Parameters:

Return VariableData TypeDescription
xmlMatching XML object

function isEmpty(xml x) (boolean )

Check whether the XML sequence is empty.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
booleanxml: Boolean flag indicating whether the XML sequence is empty

function isSingleton(xml x) (boolean )

Check whether the XML sequence contains only a single element.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
booleanxml: Boolean flag indicating whether the XML sequence contains only a single element

function parse(string xmlStr) (xml )

Parses a string as an XML.

Parameters:

Parameter NameData TypeDescription
xmlStrstringString representation of XML

Return Parameters:

Return VariableData TypeDescription
xmlParsed XML value

function remove(xml x, string xPath)

Removes the element(s) that match the given XPath.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath

function removeWithNamespace(xml x, string xPath, map namespaces)

Removes the element(s) that match the given XPath. Namespaces are supported.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
namespacesmapA map object consisting of namespaces

function select(xml x, string qname) (xml )

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

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
qnamestringQualified name of the element

Return Parameters:

Return VariableData TypeDescription
xmlAll the elements-type items in the given XML sequence, that matches the qualified name

function selectChildren(xml x, string qname) (xml )

Selects all the children of the elements in this sequence that matches the given qualified name.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
qnamestringQualified name of the element

Return Parameters:

Return VariableData TypeDescription
xmlAll the children of the elements in this sequence that matches the given qualified name

function selectDescendants(xml x, string qname) (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:

Parameter NameData TypeDescription
xxmlAn XML object
qnamestringQualified name of the element

Return Parameters:

Return VariableData TypeDescription
xmlAll the descendants that matches the given qualified name, as a sequence

function setAttributes(xml x, map attributes)

Sets the attributes to the provided attributes map.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
attributesmapAttributes map

function setChildren(xml x, xml children)

Set the children of an XML if its a singleton. An Error otherwise. Any existing children will be removed.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
childrenxmlx: An XML object

function setString(xml x, string xPath, string value)

Sets the string value of an element that matches the given XPath. If the XPath matches an existing element, that element's value will be updated. If the XPath does not match an existing element, this operation will have no effect.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
valuestringx: An XML object

function setStringWithNamespace(xml x, string xPath, string value, map namespaces)

Sets the string value of an element that matches the given XPath. If the XPath matches an existing element, that element's value will be updated. If the XPath does not match an existing element, this operation will have no effect. Namespaces are supported.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
valuestringA string value
namespacesmapA map object consisting of namespaces

function setXml(xml x, string xPath, xml value)

Sets the XML value of an element that matches the given XPath. If the XPath matches an existing element, that element's value will be updated. If the XPath does not match an existing element, this operation will have no effect.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
valuexmlAn XML value

function setXmlWithNamespace(xml x, string xPath, xml value, map namespaces)

Sets the XML value of an element that matches the given XPath. If the XPath matches an existing element, that element's value will be updated. If the XPath does not match an existing element, this operation will have no effect. Namespaces are supported.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
xPathstringAn XPath
valuexmlAn XML value
namespacesmapA map object consisting of namespaces

function slice(xml x, int startIndex, int endIndex) (xml )

Slice and return a subsequence of the an XML sequence.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object
startIndexintStart index, inclusive
endIndexintEnd index, exclusive

Return Parameters:

Return VariableData TypeDescription
xmlSliced sequence

function strip(xml x) (xml )

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

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
xmlStriped sequence

function toJSON(xml x, Options options) (json )

Converts a XML object to a JSON representation

Parameters:

Parameter NameData TypeDescription
xxmlA XML object
optionsOptionsx: A XML object

Return Parameters:

Return VariableData TypeDescription
jsonJSON representation of the given XML

function toString(xml x) (string )

Converts an XML object to a string representation.

Parameters:

Parameter NameData TypeDescription
xxmlAn XML object

Return Parameters:

Return VariableData TypeDescription
stringString value of the converted XML


Structs of ballerina.lang.xmls package

struct Options

Fields:

Field NameData TypeDescription
attributePrefixstring
preserveNamespacesboolean


Menu

  • Functions
    • addAttribute(xml x, string xPath, string name, string value)
    • addAttributeWithNamespace(xml x, string xPath, string name, string value, map namespaces)
    • addElement(xml x, string xPath, xml value)
    • addElementWithNamespace(xml x, string xPath, xml value, map namespaces)
    • children(xml x) (xml )
    • copy(xml x) (xml )
    • elements(xml x) (xml )
    • getElementName(xml x) (string )
    • getItemType(xml x) (string )
    • getString(xml x, string xPath) (string )
    • getStringWithNamespace(xml x, string xPath, map namespaces) (string )
    • getTextValue(xml x) (string )
    • getXml(xml x, string xPath) (xml )
    • getXmlWithNamespace(xml x, string xPath, map namespaces) (xml )
    • isEmpty(xml x) (boolean )
    • isSingleton(xml x) (boolean )
    • parse(string xmlStr) (xml )
    • remove(xml x, string xPath)
    • removeWithNamespace(xml x, string xPath, map namespaces)
    • select(xml x, string qname) (xml )
    • selectChildren(xml x, string qname) (xml )
    • selectDescendants(xml x, string qname) (xml )
    • setAttributes(xml x, map attributes)
    • setChildren(xml x, xml children)
    • setString(xml x, string xPath, string value)
    • setStringWithNamespace(xml x, string xPath, string value, map namespaces)
    • setXml(xml x, string xPath, xml value)
    • setXmlWithNamespace(xml x, string xPath, xml value, map namespaces)
    • slice(xml x, int startIndex, int endIndex) (xml )
    • strip(xml x) (xml )
    • toJSON(xml x, Options options) (json )
    • toString(xml x) (string )
  • Structs
    • Options

Copyright 2017 Ballerina API Documentation