Skip to content
Search
Examples

Data frame

Description

Extract data from XML files. Supports navigating to specific nodes within the document structure.

Documentation

Code

<?php

declare(strict_types=1);

use function Flow\ETL\Adapter\XML\from_xml;
use function Flow\ETL\DSL\{data_frame, ref, to_output};

require __DIR__ . '/vendor/autoload.php';

data_frame()
    ->read(
        from_xml(__DIR__ . '/data/orders.xml')
            ->withXMLNodePath('rows/row')
    )
    ->withEntry('id', ref('node')->xpath('order_id')->domElementValue())
    ->withEntry('seller_id', ref('node')->xpath('seller_id')->domElementValue())
    ->withEntry('created_at', ref('node')->xpath('created_at')->domElementValue())
    ->withEntry('cancelled_at', ref('node')->xpath('cancelled_at')->domElementValue())
    ->withEntry('discount', ref('node')->xpath('discount')->domElementValue())
    ->drop('node')
    ->collect()
    ->write(to_output(truncate: false))
    ->run();
Contributors

Built in the open.

Join us on GitHub
scroll back to top