Code Monkey home page Code Monkey logo

parser1c's Introduction

Библиотека для парсинга CommerceML 2 файлов

Основная цель данной библиотеки - парсинг XML файлов стандарта CommerceML 2 и представление данных в виде объектов.

Установка

  1. Обновите ваш composer.json файл.
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/ArtemsWay/parser1c"
    }
],
"require": {

    "artemsway/parser1c": "dev-master"
},
  1. Выполните команду composer update.

Использование

    require 'vendor/autoload.php';
    
    $importFile = 'path/to/file/import0_1.xml';
    $offersFile = 'path/to/file/offers0_1.xml';
    
    $importData = \ArtemsWay\Parser1C\Parser1C::parseImportFile($importFile);
    $offersData = \ArtemsWay\Parser1C\Parser1C::parseOffersFile($offersFile);

Выходные данные

    var_dump($importData);
    
    array:6 [▼
      "schemaVersion" => "2.07"
      "importTime" => "2017-05-13T21:41:15"
      "onlyChanges" => false
      "categories" => array:218 [▶]
      "properties" => array:608 [▶]
      "products" => array:4535 [▶]
    ]
    
    var_dump($offersData);
        
    array:6 [▼
      "schemaVersion" => "2.07"
      "importTime" => "2017-05-13T21:41:15"
      "onlyChanges" => false
      "priceTypes" => array:1 [▶]
      "warehouses" => array:2 [▶]
      "offers" => array:4535 [▶]
    ]

Дополнение

Возможен парсинг части данных.

    use ArtemsWay\Parser1C\Parser1C;
    use ArtemsWay\Parser1C\Parsers\DOM\ImportParser;
    
    $importFile = 'path/to/file/import0_1.xml';
    
    $parser = new Parser1C($importFile, new ImportParser);
    
    $partOfData = $parser->load()->parseProducts()->getData();

Есть возможность добавлять новые классы парсеров

    use ArtemsWay\Parser1C\Parsers\DOM\DOMParser;
    use ArtemsWay\Parser1C\Parsers\ParserInterface;
    
    class ContractorParser extends DOMParser
    {
        public $contractors = [];
        
        public function parseContractors()
        {
            ...
        }
    }

Использование

    use ArtemsWay\Parser1C\Parser1C;
    use ArtemsWay\Parser1C\Parsers\DOM\ImportParser;
    
    $contractorsFile = 'path/to/file/contractors0_1.xml';
    
    $parser = new Parser1C($contractorsFile, new ContractorParser);
    
    $partOfData = $parser->load()->parseAll()->getData();
ToDO
  1. Добавить SAX парсер, для уменьшения потребления RAM памяти.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.