Parser for yml(yandex.market.ru) files.
YMLParser out of box uses two types of parsing:
- XMLReader - for medium and large xml files
- SimpleXML - for small xml files
via Composer:
composer require serkin/ymlparser ~1.1
include 'vendor/autoload.php';
$filename = '/path/to/file/file.xml';
// XMLReader driver - for medium and large xml files
// SimpleXML driver - for small xml files
$parser = new \YMLParser\YMLParser(new \YMLParser\Driver\XMLReader);
$parser->open($filename); // throws \Exception if $filename doesn't exist or empty
foreach($parser->getOffers() as $offer): // YMLParser::getOffers() returns \Generator
echo $offer['url'];
endforeach;
YMLParser::getOffers() can take filter function as an argument. Filter should be an anonymous function which returns true or false
include 'vendor/autoload.php';
$filename = '/path/to/file/file.xml';
$parser = new \YMLParser\YMLParser(new \YMLParser\Driver\SimpleXML);
$parser->open($filename);
// We want offers only with not empty url subelements
$filter = function($element) { return !empty($element['url']); };
$offers = iterator_to_array($parser->getOffers($filter));
// Let's get all params from first offer if they are exist
foreach($offers[0]['params'] as $param):
echo $param['name'] . ' - ' . $param['value'];
endforeach;
- PHP: >= 5.5
- xmlrpc extension
- mbstring extension
- Send a pull request
- MIT
- getCurrencies()
- setDefaultCurrency()
- Offers price according set defaultCurrency
phpunit
You can create your own Driver. All you have to do is to implement YMLParser\Driver\DriverInterface interface in your class