flow php

UNIFIED DATA PROCESSING FRAMEWORK

composer require flow-php/etl ^0.10.0

Changelog

elephant
extract

Extracts

Read from various data sources.

arrow
transform

Transforms

Shape and optimize for your needs.

arrow
load

Loads

Store and secure in one of many available data sinks.

Definition


feature source
/**
 *  In order to iterate only over <element> nodes use `from_xml($file)->withXMLNodePath('root/elements/element')`.
 *
 *  <root>
 *    <elements>
 *      <element></element>
 *      <element></element>
 *    <elements>
 *  </root>
 *
 *  XML Node Path does not support attributes and it's not xpath, it is just a sequence
 *  of node names separated with slash.
 *
 * @param Path|string $path
 * @param string $xml_node_path - @deprecated use `from_xml($file)->withXMLNodePath($xmlNodePath)` method instead
 */
from_xml(Path|string $path, string $xml_node_path) : XMLParserExtractor

Usage Examples


Example: Data source - Xml

<?php

declare(strict_types=1);

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

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

data_frame()
    ->read(
        from_xml(__DIR__ . '/input/dataset.xml')
            ->withXMLNodePath('users/user')
    )
    ->withEntry('id', ref('node')->domElementAttributeValue('id'))
    ->withEntry('name', ref('node')->xpath('name')->domElementValue())
    ->withEntry('active', ref('node')->xpath('active')->domElementValue())
    ->withEntry('email', ref('node')->xpath('email')->domElementValue())
    ->drop('node')
    ->collect()
    ->write(to_stream(__DIR__ . '/output.txt', truncate: false))
    ->run();

Contributors

Join us on GitHub external resource
scroll back to top