Skip to content

Write XML

Type: xml-write  ·  Package: XML Activities v1.1.1  ·  Output: string

Saves an XML text to a file. It is the last step after modifying an XML with XML Set Value or XML Add Element. Returns the path written.

Writes content to the file at path. By default it formats the XML with indentation (indent = true) so it is readable; with indent = false it saves it on a single line, with no whitespace between tags.

  • Before writing, it checks that content is well-formed, safe XML (no DTD, within the package limits). See Security and limits. If it isn’t, the file is not touched.
  • It writes the <?xml version="1.0" encoding="…"?> declaration with the encoding given, even if content doesn’t carry one. With "utf-8" the file is saved with a BOM.
  • It creates any missing folders in the path and overwrites the file if it already exists.
ParameterTypeDefaultDescription
pathstring—Path of the file to write.
contentstring—The XML text to save (e.g. the output of XML Set Value).
ParameterTypeDefaultDescription
encodingstring"utf-8"File encoding (e.g. "utf-8", "utf-16", "iso-8859-1").
indentbooltrueFormat with indentation. The Designer switch or an expression that returns true/false. Since 1.1.1. Any other value is an error ('indent' must be true or false.).

Returns a string with the path of the file written (the same as path).

MessageCause and fix
'path' is required. / 'content' is required.The parameter was left empty or its expression returned null.
XML parser message with line and positioncontent is not well-formed XML (for example, you passed a text that isn’t XML).
The XML declares a DTD (<!DOCTYPE>). … / The XML is too large …The package’s security limits. See Common package errors.
.NET unsupported-encoding messageencoding is not a valid encoding name.
File system access errorNo permission on the folder, or the file is open in another program.
Read XML path = filePath → output: xml
XML Set Value xml = xml xpath = "//Status" value = "Processed" → output: newXml
Write XML path = "C:/output/invoice.xml" content = newXml → output: savedPath
Log message = "Saved to " + savedPath