Git Product home page Git Product logo

converter's Introduction

GitHub GitHub release (latest by date)

Converter ๐Ÿ“„ ๐Ÿ”„ ๐Ÿ“ƒ

Simple converter from XML to CSV or JSON or Array

Getting Started

Install with composer

by default composer will download the latest stable version.

composer require kenlog/converter

Usage - examples

Example conversion to CSV

<?php

require 'vendor/autoload.php';

use Kenlog\Converter;

// @constructor new Converter(string $xml);
$converterCSV = new Converter('products.xml');

// @method setCSV(string $csv, string $xpath, array $columns, string $separator = ',', int $skipLines = 0);
$converterCSV->setCSV('products.csv','//Product',['Code', 'Description', 'Um', 'Qty']);

// @var bool success
if ($converterCSV->success) {
    echo 'The XML file has been converted to CSV';
} else {
    echo 'The XML file was not converted to CSV';
}

Example conversion to JSON

<?php

require 'vendor/autoload.php';

use Kenlog\Converter;

// @constructor new Converter(string $xml);
$converterJSON = new Converter('products.xml');

// @method setJSON(string $jsonFile);
$converterJSON->setJSON('products.json');

// @var bool success
if ($converterJSON->success) {
    echo 'The XML file has been converted to JSON';
} else {
    echo 'The XML file was not converted to JSON';
}

Example conversion to Array

<?php

require 'vendor/autoload.php';

use Kenlog\Converter;

// @constructor new Converter(string $xml);
$converterArray = new Converter('products.xml');

// @array getArray();
$products = $converterArray->getArray();

// The result will be an array containing all records
foreach ($products['Product'] as $product) {
    echo $product['Code'] . PHP_EOL;
    echo $product['Description'] . PHP_EOL;
    echo $product['Um'] . PHP_EOL;
    echo $product['Qty'] . PHP_EOL;
}

๐Ÿ‘ท Any contribution will be highly appreciated

Clone the repository:

git clone https://github.com/kenlog/converter.git

๐Ÿ› Issues

Please create an issue for any bugs you've found.

Author

License

This project is licensed under the MIT License - see the LICENSE.md file for details

converter's People

Contributors

kenlog avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.