toxml() Function

Converts a value to its equivalent XML form.

Syntax

toxml( value, format, name, namespace )

value: (Any Type) The value or variable (PV, ACP) to be converted to XML.

format: (Boolean) Whether or not to format the result. If true, the resultant XML is formatted with line breaks and indenting, otherwise it uses a compact notation. If not given, the result is unformatted XML.

name: (Text) The name to use as the root element name in the resultant XML. If not given, the name of the data type of the variable passed as the value parameter is used.

namespace: (Text) The namespace to use as the default namespace in the resultant XML. If not given, the namespace of the data type of the variable passed as the value parameter is used.

Returns

Text

Notes

This function supports primitive system data types, custom data types, and the following complex system data types: LabelValue, LabelValueTable, PagingInfo, SortInfo, and DataSubset.

The XML structure for Complex System Data Types and Appian objects is not guaranteed to remain the same from release to release.

Examples

You can copy and paste these examples into the Expression Rule Designer to see how this works.

1
toxml(a!paginginfo(startIndex: 1, batchSize: 10))

returns

1
2
3
4
<a:PagingInfo xmlns:a="http://www.appian.com/ae/types/2009">
 <startIndex>1</startIndex>
 <batchSize>10</batchSize>
</a:PagingInfo>

A well-formed XML document has a single root element. When you pass a list into toxml(), you get an XML snippet of multiple elements. To end up with a single-root XML document when passing in a list, use a parent-level xml element.

By wrapping it with a root element, you end up with a well-formed single-root XML document.

1
2
3
4
a!localVariables(
  local!data:{{ id: 1, value: "First value"}, { id: 2, value: "Second Value"}},
  "<root>" & toxml(local!data) & "</root>"
)

returns

1
2
3
4
<root>
  <a:Dictionary xmlns:a="http://www.appian.com/ae/types/2009" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><id xsi:type="xsd:int">1</id><value xsi:type="xsd:string">First value</value></a:Dictionary>
  <a:Dictionary xmlns:a="http://www.appian.com/ae/types/2009" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><id xsi:type="xsd:int">2</id><value xsi:type="xsd:string">Second Value</value></a:Dictionary>
</root>
Open in Github Built: Thu, Feb 23, 2023 (02:59:22 PM)

On This Page

FEEDBACK