Write data to XML file.
Documentation
Example: Xml
Topic: Data writing
Description
composer.json
{
"name": "flow-php/examples",
"description": "Flow PHP - Examples",
"license": "MIT",
"type": "library",
"require": {
"flow-php/etl": "1.x-dev",
"flow-php/etl-adapter-xml": "1.x-dev"
}
}
code.php
<?php
declare(strict_types=1);
use function Flow\ETL\Adapter\XML\to_xml;
use function Flow\ETL\DSL\{data_frame, from_array, overwrite};
require __DIR__ . '/vendor/autoload.php';
data_frame()
->read(
from_array([
['id' => 1, 'name' => 'John', 'age' => 30],
['id' => 2, 'name' => 'Jane', 'age' => 25],
['id' => 3, 'name' => 'Bob', 'age' => 35],
['id' => 4, 'name' => 'Alice', 'age' => 28],
['id' => 5, 'name' => 'Charlie', 'age' => 32],
])
)
->collect()
->mode(overwrite())
->write(to_xml(__DIR__ . '/output.xml'))
->run();
Output
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row><id>1</id><name>John</name><age>30</age></row>
<row><id>2</id><name>Jane</name><age>25</age></row>
<row><id>3</id><name>Bob</name><age>35</age></row>
<row><id>4</id><name>Alice</name><age>28</age></row>
<row><id>5</id><name>Charlie</name><age>32</age></row>
</rows>