1. Go to this page and download the library: Download byjg/anydataset-xml library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
byjg / anydataset-xml example snippets
$xml = file_get_contents('example1.xml');
$dataset = new \ByJG\AnyDataset\Xml\XmlDataset(
$xml, // The Xml
"book", // The node that represents a row
[
"category" => "@category",
"title" => "title",
"lang" => "title/@lang",
"lang2" => function ($row) {
return substr($row->get('lang'), 0, 2);
}
] // Mapping columns
);
$iterator = $dataset->getIterator();
foreach ($iterator as $row) {
echo $row->get('category'); // Print COOKING, CHILDREN, WEB
echo $row->get('title'); // Print Everyday Italian, Harry Potter, Learning Xml
echo $row->get('lang'); // Print en-US, de-DE, pt-BR
echo $row->get('lang2'); // Print en, de, pt
}