GithubHelp home page GithubHelp logo

exhale's Introduction

Exhale exporter framework

Easy to use xml data exporter library designed for WordPress. It uses sabre/xml library to produce clean results.

Installation

This isn't yet available in packagist so you need to add the repository as well

$ composer config repositories.repo-name vcs https://github.com/devgeniem/exhale
$ composer require devgeniem/exhale:dev-master

Example

// Create new exporter with basic data
$food_exporter = new Exhale\Exporter( [
    // This is example of basic xml node
    [
        'name' => 'kebab',
        'value'=> 'Iskender',
        'attributes' => [
            'price' => '5€'
        ]
    ],

    // You can put nested elements in value too, all of them will be parsed recursively
    [
        'name' => 'partypack',
        'attributes' => [
            'price' => '20€'
        ],
        'value'=> [
            'pizza' => 'Quattro Formaggi',
            'salad' => 'chicken',
            'drink' => 'Pepsi'
        ]
    ],

    // Elements can also be like key -> value
    // But beware, now you can't have two elements with same name as the other will get wiped out
    'pizza' => 'Margherita'
] );

// It's also possible to push one item
$food_exporter->push_item('salad', 'falafel' );
$food_exporter->push_item('salad', 'chicken', ['price' => '10$'] );

// Wrap all elements in Foods element with custom attributes, namespaces are also added into this location
$food_exporter->set_root_element( [
    'name' => 'Foods',
    'attributes' => [
        'xsi:noNamespaceSchemaLocation' => 'canonical_model.xsd'
    ]
] );

// If your xml specification has namespaces
$food_exporter->add_xml_namespace( [ 'http://www.w3.org/2001/XMLSchema-instance' => 'xsi' ] );
$food_exporter->add_xml_namespace( [ 'http://localhost/functions' => 'f' ] );

// Create endpoint for the site
// After this the site will response with xml in your path
$food_exporter->create_wp_endpoint( '/api/export/food.xml', 'xml' );

// You can also export the data as xml
$xml_string = $food_exporter->to_xml();

This will generate a xml response like:

<?xml version="1.0" encoding="UTF-8"?>
<Foods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:f="http://localhost/functions" xsi:noNamespaceSchemaLocation="canonical_model.xsd">
 <kebab price="5€">Iskender</kebab>
 <partypack price="20€">
  <pizza>Quattro Formaggi</pizza>
  <salad>chicken</salad>
  <drink>Pepsi</drink>
 </partypack>
 <pizza>Margherita</pizza>
 <salad>falafel</salad>
 <salad price="10$">chicken</salad>
</Foods>

Maintainers

Onni Hakala

License

MIT

exhale's People

Contributors

onnimonni avatar

Watchers

Hannu Kumpula avatar Cheer Up Emo Kid avatar James Cloos avatar Jussi Löf avatar villesiltala avatar Villehard Pietarinen avatar  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.