Skip to content

Data to XML

The Data to XML component is designed to help you transform your internal data structures into a widely used standard format called XML. If you have data organized in lists or dictionaries (key-value pairs), this component takes that information and converts it into a structured text format known as XML. This is particularly useful when you need to share data with other systems, save it for later use, or send it to applications that specifically require XML input.

How it Works

Think of this component as a translator. When you provide it with data—such as a list of customer records or a configuration file—it looks at the structure of that data (the keys and values). It then automatically builds an XML document by creating “tags” for your keys and placing your values inside them.

For example, if you have data like {"name": "John", "age": 30}, the component wraps “name” and “age” in XML tags and places “John” and “30” inside, resulting in a clean, standard XML string. You don’t need to manually write the XML code; the component handles the formatting for you, ensuring that the hierarchy of your data is preserved correctly.

Connection & Credentials

This component does not require any external credentials or API connections. It processes data locally within your Nappai workflow.

Operations

This component does not have multiple operations. It performs a single, automatic serialization process.

Inputs

This component has a special mode called “Mapping Mode”. When you enable this mode using the toggle switch, an additional input called “Mapping Data” is activated, and each input field offers you three different ways to provide data:

  • Fixed: You type the value directly into the field.
  • Mapped: You connect the output of another component to use its result as the value.
  • Javascript: You write Javascript code to dynamically calculate the value.

This flexibility allows you to create more dynamic and connected workflows.

Input Fields

The following fields are available to configure this component. Each field may be visible in different operations:

  • Data: [Data object to serialize as XML text]. This is the main input where you provide the structured data (like a dictionary or list) that you want to convert. This input is required.
    • Visible in: Perform Action

Outputs

The component produces a single output:

  • XML Output: This is the final result in XML text format. You can use this output to send the data to other components that accept text input, such as file writers, HTTP senders, or database savers.

Output Data Example (JSON)

Below is an example of what the output looks like after the component processes a sample input. Note that the output is a string containing valid XML code. json { “xml_output”: “\n John Doe\n 30\n <is_active>true</is_active>\n” }

Connectivity

Since this is a data transformation component, it is typically placed in the middle of a workflow. You should connect the output of data-gathering or data-preparation components (like data readers or variable setters) to the Data input of this component.

The resulting XML Output is commonly connected to:

  • File Writer components: To save the XML data to a local file.
  • HTTP Sender components: To send the XML payload to an external API or server.
  • Text Editors: For further manipulation or display.

Usage Example

Imagine you are building a workflow that exports user profiles to a backup system.

  1. You have a component that retrieves a user’s details from a database as a dictionary: {"username": "alice", "role": "admin"}.
  2. You connect this dictionary output to the Data input of the Data to XML component.
  3. The Data to XML component converts this dictionary into an XML string.
  4. You then connect the XML Output of this component to a Save to File component, which saves the XML text to a .xml file on your server.

This allows you to store user data in a standard, readable format that other systems can easily understand.

Tips and Best Practices

  • Ensure your input data is a valid dictionary or list; complex objects that cannot be easily serialized might cause errors.
  • Use this component when you need interoperability, as XML is a standard format used by many legacy and external systems.
  • If you are working with large datasets, consider enabling “Mapping Mode” to process data efficiently in batches if supported by your workflow structure.

Security Considerations

When generating XML from user-provided data, be aware of potential XML Injection vulnerabilities. Ensure that any input data coming from external users is sanitized or validated before it reaches this component to prevent malicious XML content from being generated or processed.