XML

◷ Reading Time: 4 minutes

toXml

Creates XML object from a source input

source |toXml (defaultNamespace, autoPrefix)
  • source: a string representation of an XML, or an XML document.
  • return: an XML object that can be manipulated using related monads
  • defaultNamespace: the prefix of default namespace to discover and register namespaces automatically
  • autoPrefix: true to use xpath prefixed with default namespaces, default is false

xmlPlain

Remove all namespaces of an XML object

xml |xmlPlain ()
  • return: the XML object without the namespaces

xmlNamespaces

Returns all namespaces of an XML object

xml |xmlNamespaces ()
  • return: a collection of string representations of all namespaces of the document

xmlDefaultNamespace

Returns the default namespace of an XML object

xml |xmlDefaultNamespace ()
  • return: The default namespace of xml document

xmlElements

Returns list of elements of a node based on an xpath

xmlNode |xmlElements (xpath)
  • xpath: (Mandatory) a valid xpath address in the document

xmlElement

Returns a single element of a node based on an xpath

xmlNode |xmlElement (xpath)
  • xpath: (Mandatory) a valid xpath address in the document

xmlAttribute

Returns an attribute element of a node based on an xpath. It also can set value of an attribute.

xmlNode |xmlAttribute (attributeName, attributeValue)
  • attributeName: (Mandatory) name of attribute
  • attributeValue: an [expression]. When this is set, it changes the value of an attribute when it exists, otherwise it adds an attribute with a name and value provided.

xmlAttributes

Returns all of the attributes of a collection of nodes based on an xpath. It also can set the values of all attributes.

xmlNode |xmlAttributes (attributeName, attributeValue)
  • attributeName: (Mandatory) name of attribute
  • attributeValue: an [expression]. When this is set, it changes the value of an attribute when it exists, otherwise it adds an attribute with a name and value provided.

xmlValue

Returns or sets value of element or attributes.

To return the value:

xmlNode |xmlValue ()

To set the value:

xmlNode |xmlValue (value)

xmlValues

Returns a list of values of element or attributes.

xmlNode |xmlValues ()

xmlNodes can be one or a list of nodes. Still the result will be a list with one or many values.

xmlNew

Creates a new element inside the xml node.

xmlNode |xmlNew (name)
  • name: (Mandatory) This is the name of a new element.

xmlRemove

Removes the current element and all of its children. If the node is an attribute, it removes the attribute from the node and returns the element. If the current element is a node, it deletes the node and all of its children, and will return the parent of the node.

xmlNode |xmlRemove ()

xmlParent

Returns the parent of a node.

xmlNode |xmlParent (level)
  • level: (Optional) Number of levels to navigate up the hierarchy. If not provided, default is one, which means the parent of the current xmlNode.

xmlParents

Returns all of the parents of a collection of nodes.

xmlNodes |xmlParents ()
Updated on June 8, 2020

Was this article helpful?

Related Articles