1. Overview
XML (Extensible Markup Language) is a standard and flexible text-based format for representing structured data. It is widely used for data exchange between different systems and for configuration files.
The GoInsight Xml node is a powerful utility for seamless data transformation within your workflows. It allows you to convert data between the two most common structured data formats, JSON and XML, enabling interoperability between various APIs and services. With this node, you can:
- Convert a JSON string into a well-formed XML string.
- Transform an XML string back into a JSON string.
2. Prerequisites
This is a built-in utility node and does not require any external accounts or special setup to use.
3. Credentials
For detailed instructions on how to obtain and configure credentials, please refer to our official documentation: Credentials Configuration Guide.
4. Supported Operations
This section provides a summary of the operations available for the Xml node, followed by detailed descriptions of their parameters and outputs.
Summary
The node's operations are focused on data format conversion.
| Resource | Operation | Description |
|---|---|---|
| Data Conversion | JSON to XML | Converts a JSON string into an XML string. |
| Data Conversion | XML to JSON | Converts an XML string into a JSON string. |
Operation Details
JSON to XML
Converts a JSON string into an XML string.
Input Parameters:
- JSON: A JSON string to be converted into XML.
Options:
- RootTag: Name of the single top-level XML element that wraps the entire document.
- ItemTag: Tag name used for each array/list element when serializing lists to XML.
Output:
- Xml (string): The resulting XML string. Empty if conversion failed.
- Success (bool): Indicates whether the conversion was successful.
- ErrorMessage (string): Error description if conversion failed; empty otherwise.
XML to JSON
Converts an XML string into a JSON string.
Input Parameters:
- XML: An XML string to be converted into JSON.
Output:
- JSON (string): The resulting JSON string. Empty if conversion failed.
- Success (bool): Indicates whether the conversion was successful.
- ErrorMessage (string): Error description if conversion failed; empty otherwise.
5. Example Usage
This section will guide you through creating a simple workflow to convert a JSON object into an XML string.
The workflow will consist of three nodes: Start -> Xml -> Answer.
- Add the Xml Node
- In the workflow canvas, click the "+" icon to add a new node.
- In the panel that appears, select the "Tools" tab.
- Find and select "Xml" from the list of tools.
- From the list of supported operations for Xml, click on "JSON to XML" to add the node to your canvas.
- Configure the Node
- Click on the newly added "JSON to XML" node to open its configuration panel on the right.
- Credentials: This node is a built-in utility and does not require credentials.
- Parameters: Fill in the required input parameters.
- JSON: In this field, provide the JSON string you want to convert. You can either type it directly, or use a variable reference from a previous node (e.g., {{$get_data.output.body}}). For this example, let's enter the following static JSON:
- RootTag (Optional): You can specify a custom root element for your XML. If you leave this blank, it defaults to root. Let's enter OrderDetails here.
- ItemTag (Optional): This defines the tag name for elements within an array. The default is item. Our JSON already uses item, so we can leave this blank to use the default.
- Run and Validate
- Once all required parameters are correctly filled, any error indicators on the workflow canvas will disappear.
- Click the "Run" button in the top-right corner of the canvas to execute the workflow.
- After a successful execution, you can click the log icon in the top-right corner to view the detailed input and output of the node, verifying that the conversion was successful and the output XML is correct. The output Xml field should contain a string similar to ....
After completing these steps, your workflow is fully configured. When executed, it will take the provided JSON data and convert it into a structured XML string, which can then be used in subsequent steps of your automation.
6. FAQs
Q: Why is my conversion failing with Success set to false?
A: The most common cause of conversion failure is malformed input data.
- For JSON to XML: Ensure the input string is a valid, well-formed JSON. Common errors include missing commas, incorrect bracket usage, or unquoted keys.
- For XML to JSON: Ensure the input string is valid XML with properly closed tags and a single root element.
You can use an online validator to check your data structure. Also, inspect the ErrorMessage output field on the node for a specific error description.
Q: How are JSON arrays converted to XML?
A: When converting a JSON array to XML, each element in the array is wrapped in an XML tag. By default, this tag is named . You can customize this tag name by providing a different value in the optional ItemTag parameter in the JSON to XML operation.
7. Official Documentation
XML is a universal standard maintained by the World Wide Web Consortium (W3C). For detailed specifications and technical information, you can refer to the official documentation.
Leave a Reply.