# XML File Destination

Astera’s *XML/JSON File Destination* object provides the functionality to write data to an XML or JSON file when the data is in hierarchical format.

### Video

{% embed url="<https://www.youtube.com/watch?v=mWdoPPFjO0c>" %}

### Use Case

In order to understand how to write to an *XML/JSON File Destination* object, we will take help of a use-case where we will convert flat datasets to an hierarchical set, and then write the transformed data to an XML file.

*Customers* and *Orders* data from database tables will be used as source objects. We will then join them using the *TreeJoin* Transformation to create a hierarchical dataset.

Learn more about how the [*Tree join Transformation*](https://documentation.astera.com/astera-data-stack-v10/dataflows/transformations/tree-join-transformation) works in Astera.

<figure><img src="https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FZXmeaq5srZuSTpe0tJGH%2FUse%20Case.png?alt=media&#x26;token=0b61e671-53a6-4f19-9e75-04ed558d8a46" alt=""><figcaption></figcaption></figure>

### Configuring the XML/JSON File Destination Object

* To get an *XML/JSON File Destination* object from the Toolbox, go to *Toolbox > Destinations > XML/JSON File Destination* and drag-and-drop it onto the designer. If you are unable to see the Toolbox, go to *View > Toolbox* or press Ctrl + Alt + X.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fqh9faZnqBVqpzzDvSwZ7%2F1.png?alt=media\&token=c1ac4f90-b3d2-48ad-9243-853c1d8d0295)

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F0fkJrkqsNPyP0eiUva3r%2F2.png?alt=media\&token=ef76cb21-bdf5-446f-a902-3657664ded5a)

The dragged destination object is empty right now. This is because the object has not been configured yet.

{% hint style="info" %}
**Note:** In this case we will be using the use case discussed earlier, taking the *Treejoin* as the source for data to write to the *XML/JSON File Destination.*
{% endhint %}

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FUo2ORBhxfucuOgBYCCpO%2F3.png?alt=media\&token=3c4c49eb-f5ca-4c35-a712-6b746eeb98e3)

#### Creating a Schema File

A schema file is needed to write data to an *XML/JSON File Destination*. To create the schema file, right click on the source object (*Treejoin* transformation in this case), a context-menu will appear, select the option *Generate XML Schema for layout*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FZFZVOPcEAkmyfiaapBFO%2F4.png?alt=media\&token=cac85db9-f9bc-4ee5-8ea7-d646c5af929b)

* A new dialog box will open where you will be asked to save the XML schema file. Give the *File Name* and file path for the schema file and click *Save*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FvZt6ZepMLHSsZ8gX2QvE%2F5.png?alt=media\&token=06c66071-4718-48d1-8f39-7fc29727835a)

* The schema file has been created in the specified location. To view this file, go to the file location and open the file in Astera.

  * The opened file would look like the one below:

  ![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FCsoKOtJLqcApn2latSlH%2F6.png?alt=media\&token=461ed759-f58f-48c6-8121-52e107fcff2e)

#### File Path

* To configure the *XML/JSON File Destination* object, right-click on its header and select *Properties* from the context-menu.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FyRGLuFreTTaqixnQpmHl%2F7.png?alt=media\&token=b73d5c60-95a0-4f82-85df-b069a5df9cb7)

* A window, *Destination XML File*, will open. Here we will specify the file locations; *File Path* and *Schema File* for the *XmlJsonDest* object.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FYCQ2KG5QIBhtXyVkOQ5b%2F8.png?alt=media\&token=2e416769-2563-49a0-bd2b-74ebbaddd86b)

* The destination file will now be saved in the provided file location. Click *OK*, and map the destination object to the source object before further configuration.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2Fv2fqEdjhTzk5W1rbFXla%2F9.png?alt=media\&token=dc1487b0-8094-40bb-94e4-ae9fb009c694)

* The *XmlJsonDest* object will now have the layout of the source object (*Treejoin* Transformation in this case).

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F7GRcMmmRrWrZHNYy2VX3%2F10.png?alt=media\&token=fbc9f022-7894-46c3-b76d-a041bb24ea03)

#### Mapping

* To map the source object to the destination object, the following ways of mapping can be used:

  * By dragging and dropping the parent node of the source object (*TreeJoin* node in the *TreeJoin* table) onto the child node of the destination object (*TreeJoin* node in the *XmlJsonDest* object) for automatic mapping.

  ![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FX7e8ykXqlbKZPrvakB8Y%2F11.png?alt=media\&token=701d466f-255e-4dc6-9fc7-0289892f7d85)

  * By manually mapping the source parent node (*TreeJoin* in the *TreeJoin* table) by dragging it to the respective destination child node (*TreeJoin* in the *XmlJsonDest* object).

  ![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FV4y434W70WZ23kkSTnXG%2F12.png?alt=media\&token=838e4e9e-3ac0-40fc-8c1a-b1feb77c9517)
* The fields are now mapped.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FMRfRk6eJQzLyYaPmXbRJ%2F13.png?alt=media\&token=4f482acd-ca97-4b78-8509-954e73e11cd6)

#### Properties

Once the file locations have been specified and the mappings have been done, further properties can be defined.

***XML Layout***

* The next window after the *Destination XML File* window is the *XML Layout* window.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FBf2VvWSx6ti58K2slehv%2F14.png?alt=media\&token=10f12ab8-09b3-4c52-87a8-5bee28f301d0)

* This window shows the XML layout for the *XmlJsonDest* object. The collection nodes for the object can be seen in this window with their fields.

***Config Parameters***

* Click *Next*, and a window, *Config Parameters*, will open, which will allow us to further configure and define parameters for the *XML/JSON Destination* object.

  Parameters can provide easier deployment of flows by eliminating hardcoded values and provide an easier way of changing multiple configurations with a simple value change.

{% hint style="info" %}
**Note**: Parameters left blank will use their default values assigned on the properties page.
{% endhint %}

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FeJkZpMlOt94MYcUIS6tE%2F15.png?alt=media\&token=5a00320f-6df8-46e8-9ff9-299441b841aa)

***General Options***

* Click *Next*, and a new window, *General Options,* will open. On this window:

  * *Comments* can be added.
  * *General Options* are given, which relate to processing of records in the destination file.

  ![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FJzzd84xhG6tQo1udHE5l%2F16.png?alt=media\&token=06fa12fc-6f28-45ed-a01e-0a292d85dadf)
* Click *OK*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FjR0xpxqXqSw0meJhAxhw%2F17.png?alt=media\&token=75ffa48f-43c8-436e-9dad-48263a19aa46)

The *XmlJsonDest* object has been successfully configured and the destination file can now be created by running the dataflow.
