FormatXML

You can use this function for Optiva Workflows.

Purpose

Changes the XML declaration node, if available, to the requested encoding and indents the XML for a better read. The function can re-encode the XML to UTF-8 which matches the encoding used when the string is saved to a file on disk.

Syntax


Public Function FormatXML(XML As String, ForceEncoding As Short, Indent As Boolean) As String

Arguments

Part Type Description
XML String The XML content itself.
ForceEncoding Short Changes the XML declaration node, if available, to the requested encoding.
  • 0 = UTF8
  • 1 = Unicode
  • 2 = UTF32
  • 3 = UTF7
Indent Boolean Indents the XML content.

Examples

This example shows how to force UTF-8 encoding and indent the XML.

Dim xml As String = ObjectXML(_ObjectSymbol, _ObjectKey, "HEADER;STATUS;PER")
Dim prettyXML As String = FormatXML(xml, 0, True)

The XML is indented for a better read, but it results in more memory or disk usage.

This example shows how encoding is changed for the XML.

' Assuming some remote service provided the following UTF-16 encoded XML
Dim xmlFromRemoteService As String = "<?xml version=""1.0"" encoding=""utf-16""?><fsxml><formula>...
Dim utf8XML As String = FormatXML(xmlFromRemoteService, 0, False)
' Results in: <?xml version="1.0" encoding="utf-8"?><fsxml><formula>...