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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
name | string | Name of the attribute to be added |
value | string | Attribute 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
name | string | Name of the attribute to be added |
value | string | Attribute value |
namespaces | map | A 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
value | xml | An 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
value | xml | An XML value |
namespaces | map | A 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml |
function copy(xml x) (xml )
Make a deep copy of an XML.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml |
function elements(xml x) (xml )
Get all the items that are of element type in an XML sequence.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml |
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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string |
function getString(xml x, string xPath) (string )
Evaluates the XPath on an XML object and returns the matching string value.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | Matching 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
namespaces | map | A map object consisting of namespaces |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | Matching 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string |
function getXml(xml x, string xPath) (xml )
Evaluates the XPath on an XML object and returns the matching XML object.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml | Matching 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
namespaces | map | A map object consisting of namespaces |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml | Matching XML object |
function isEmpty(xml x) (boolean )
Check whether the XML sequence is empty.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean |
function isSingleton(xml x) (boolean )
Check whether the XML sequence contains only a single element.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
boolean |
function parse(string xmlStr) (xml )
Parse and get an XML from a string .
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
xmlStr | string | String representation of XML |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml |
function remove(xml x, string xPath)
Removes the element(s) that match the given XPath.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
function removeWithNamespace(xml x, string xPath, map namespaces)
Removes the element(s) that match the given XPath. Namespaces are supported.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
namespaces | map | A 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
qname | string | Qualified name of the element |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml |
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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
qname | string | Qualified name of the element |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml |
function setAttributes(xml x, map attributes)
Sets the attributes to the provided attributes map.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
attributes | map | Attributes 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
children | xml | x: 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
value | string | x: 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
value | string | A string value |
namespaces | map | A 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
value | xml | An 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
xPath | string | An XPath |
value | xml | An XML value |
namespaces | map | A 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 Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
startIndex | int | Start index, inclusive |
endIndex | int | End index, exclusive |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml |
function strip(xml x) (xml )
Strips any text items from an XML sequence that are all whitespace.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
xml |
function toString(xml x) (string )
Converts an XML object to a string representation.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
x | xml | An XML object |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | String value of the converted XML |