from_xml
Definition
/**
* 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
<?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();