XML to Data
This component is designed to take input in the form of XML (Extensible Markup Language) text and convert it into a structured data object. XML is a common format for storing and transporting data, often used in web services, configuration files, and data exchange between applications.
In the Nappai dashboard, this component acts as a bridge. It takes raw XML text and parses it, creating a hierarchical structure (like a tree) of data. This structured data can then be passed to other components for further processing, analysis, or integration into your automation flows. Essentially, it turns a block of code-like text into a readable, usable data structure.
How it Works
When you use this component, it reads the XML content you provide. It understands the structure of XML, which includes tags (like <name> or <price>), attributes (properties of tags), and text content.
- Parsing: The component analyzes the XML syntax to ensure it is valid. It builds a mental “map” of the data, recognizing which parts are children of others, creating a nested structure.
- Transformation: It converts this raw text into a Data object. In simple terms, it changes the text string into a list of items or a dictionary-like structure where you can access specific pieces of information by their names.
- Mode Selection: You can choose how to provide the input:
- Data Entry: Connect to another component that already outputs data in XML format.
- Manual Entry: Type or paste the XML text directly into the component.
The output is a structured object that retains the relationship between different parts of your XML. For example, if you have an XML file for a product list, the output will be a structure where you can easily access “Product 1,” “Product 2,” and their respective details like “Price” or “Name” without having to read the raw text.
Connection & Credentials
This component does not require any external credentials or API keys to function. It works locally within your Nappai workflow to process the text you provide.
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:
- XML Data: [Data object containing XML text to parse into a structured Data object.]
- XML Text: [Enter XML text manually to parse into a structured Data object.]
- Mode: [Choose between connecting a Data object (Data Entry) or typing XML content manually (Manual Entry).]
Outputs
- Data: [A structured data object derived from the parsed XML. This output contains the hierarchical information from your XML, organized in a way that allows other components to access specific values, attributes, or lists.]
Output Data Example (JSON)
Below is an example of what the Data output might look like if you provided the following XML:
xml
The resulting structured data object (often represented in workflows for mapping) would allow you to access: json { “root”: { “person”: { “name”: “John Doe”, “age”: “30” } } }
Note: The exact structure depends on how the Nappai system maps the XML nodes to data structures, but it will always preserve the hierarchy (Parent -> Child -> Grandchild).
Connectivity
Typically, this component is connected from components that generate or store XML data (such as a Web Request component that receives an XML response, or a File Reader component reading an XML file).
It is connected to components that require structured data for analysis or transformation. Common next steps include:
- Data Transformation Components: To clean, filter, or reshape the data.
- AI Assistant Components: To analyze the content of the parsed data.
- Database Writers: To insert the structured data into a database.
- UI Elements: To display specific values from the XML in a dashboard widget.
Usage Example
Scenario: Parsing a Weather Forecast
- Input: You use a Web Request component to fetch weather data from a free API that returns data in XML format.
- Transformation: You connect the output of the Web Request to the XML to Data component.
- In the Mode field, select “Data Entry” (since you are connecting from another component).
- Output: The XML to Data component outputs a Data object containing the weather information.
- Next Step: You connect the Data output to a Select Fields component or an AI Assistant component to extract just the “Temperature” and “Description” from the structured data.
Tips and Best Practices
- Validate XML First: Ensure your XML input is well-formed (correct tags, closed tags) before sending it to this component. Invalid XML will cause the component to fail.
- Use Mapping Mode for Dynamic Data: If you are building a complex workflow where the XML structure might vary, enable Mapping Mode to flexibly map specific parts of the data to subsequent components.
- Manual Entry for Testing: When building or debugging your workflow, use the XML Text input with Mode: Manual Entry to quickly test the component with small samples of code.
- Keep Data Small for Debugging: When testing, use small XML snippets to make it easier to verify that the structure is correct before processing large datasets.
Security Considerations
- Input Validation: Always ensure that the XML source is trusted. Parsing untrusted XML can sometimes lead to security vulnerabilities (like XML External Entity attacks). If you are processing XML from external users or unreliable sources, ensure your Nappai instance has appropriate sanitization measures.
- Data Privacy: Be mindful of what data is contained in the XML. Since this component parses all visible tags, ensure no sensitive personal information (PII) is unintentionally exposed in your workflow logs if they are visible.