Write XML
Write XML
Section titled “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.
How it works
Section titled “How it works”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
contentis 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 theencodinggiven, even ifcontentdoesn’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.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Path of the file to write. |
content | string | — | The XML text to save (e.g. the output of XML Set Value). |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
encoding | string | "utf-8" | File encoding (e.g. "utf-8", "utf-16", "iso-8859-1"). |
indent | bool | true | Format 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.). |
Output
Section titled “Output”Returns a string with the path of the file written (the same as path).
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'path' is required. / 'content' is required. | The parameter was left empty or its expression returned null. |
| XML parser message with line and position | content 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 message | encoding is not a valid encoding name. |
| File system access error | No permission on the folder, or the file is open in another program. |
Example
Section titled “Example”Read XML path = filePath → output: xmlXML Set Value xml = xml xpath = "//Status" value = "Processed" → output: newXmlWrite XML path = "C:/output/invoice.xml" content = newXml → output: savedPathLog message = "Saved to " + savedPathRelated activities
Section titled “Related activities”- Read XML — read an XML file.
- XML Set Value / XML Add Element — modify before saving.