Ymlparser
Parser for yml(yandex.market.ru) files
Install / Use
/learn @serkin/YmlparserREADME
YML Parser
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
Installation
via Composer:
composer require serkin/ymlparser ~1.1
Usage
Getting all offers from file
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;
Getting all offers from file with applied filter
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;
Dependencies
- PHP: >= 5.5
- xmlrpc extension
- mbstring extension
Contribution
- Send a pull request
Licence
- MIT
TODO
- getCurrencies()
- setDefaultCurrency()
- Offers price according set defaultCurrency
Tests
phpunit
It is extensible
You can create your own Driver. All you have to do is to implement YMLParser\Driver\DriverInterface interface in your class
Related Skills
node-connect
352.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
