2017 © Pedro Peláez
 

library xml-mapper

XMLMapper for Laravel and PHP

image

edujugon/xml-mapper

XMLMapper for Laravel and PHP

  • Monday, May 14, 2018
  • by edujugon
  • Repository
  • 2 Watchers
  • 25 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 17 Versions
  • 7 % Grown

The README.md

XMLMapper for Laravel and PHP

Are you working with xml data? then this package is for you. This is the simplest API to interact with XML data., (*1)

Installation

type in console:, (*2)

composer require edujugon/xml-mapper

Laravel 5.*

Laravel 5.5 or higher?, (*3)

Then you don't have to either register or add the alias, this package uses Package Auto-Discovery's feature, and should be available as soon as you install it via Composer., (*4)

(Laravel < 5.5) Register the XMLMapper service by adding it to the providers array., (*5)

'providers' => array(
    ...
    Edujugon\XMLMapper\Providers\XMLMapperServiceProvider::class
)

(Laravel < 5.5) Let's add the Alias facade, add it to the aliases array., (*6)

'aliases' => array(
    ...
    'XMLMapper' => Edujugon\XMLMapper\Facades\XMLMapper::class,
)

Usage samples

$mapper = new Edujugon\XMLMapper\XMLMapper();
$mapper->loadXML($xmlData);

or, (*7)

$mapper = new Edujugon\XMLMapper\XMLMapper($xmlData);

or with Laravel Facade, (*8)

$mapper = XMLMapper::loadXML($xmlData);

Don't forget to use the facade use statement at the top of your class: use Edujugon\XMLMapper\Facades\XMLMapper;, (*9)

Get value

You must know the tags path. Otherwise you should use findValue., (*10)

$value = $mapper->getvalue(['first-tag','second-tag','my-tag']);

The above example takes the value of the tag with name my-tag., (*11)

If no parameter passed to the method it looks up the value of the first (parent) tag., (*12)

Get attribute

You must know the tags path. Otherwise you should use findAttribute., (*13)

$att = $mapper->getAttribute('id',['first-tag','second-tag','my-tag']);

The above example returns the value of the id attribute in my-tag., (*14)

Get element

Get a new instance of XMLMapper but with the tag-name element as base xml., (*15)

$newXmlMapper = $mapper->getElement('tag-name');

Get elements

Get an array of XMLMapper objects based on the tag-name xml element., (*16)

$arrayOFXmlMappers = $mapper->getElement('tag-name');

Find value

$value = $mapper->findValue('my-tag');

It looks for the first tag called my-tag and returns its value., (*17)

Find attribute

Get the attribute value of a tag., (*18)

$att = $mapper->findAttribute('my-att','my-tag');

It looks for the first tag called my-tag, then try to find my-att as attribute and returns its value., (*19)

If no tag passed, it takes the first attribute matching the provided attribute name:, (*20)

$att = $mapper->findAttribute('my-att');

Find attribute by condition

Loop through all elements trying to match the condition/s. When found, returns the value of the provided attribute., (*21)

$att = $mapper->findAttributeWhere('my-att',['id'=>1,'dev'=> 'edu',['name','!=','john']])

Check allowed where operators, (*22)

Find attributes of a tag

Get an object with those attributes as object properties. First it searches the tag and then retrieves the requested attributes., (*23)

$obj = $mapper->findAttributes(['att-1','att-2'],'my-tag')

$name = $obj->name;
$dev = $obj->dev;

If no tag provided, it takes the first tag that has those attributes and return the values., (*24)

Find attributes by condition

Loop through all elements trying to match the condition/s. When found, returns an object with those attributes as object properties., (*25)

$obj = $mapper->findAttributesWhere(['att-1','att-2'],['dev'=> 'edu',['name','!=','john']])

Check allowed where operators, (*26)

Find all attributes of a tag

Get an array of objects with the tag attributes as properties, (*27)

$list = $mapper->findAllAttributesOf('tag-name');

Find all attributes of a tag by condition

Get an array of objects with attributes as properties matching the provided tag name and condition., (*28)

$list = $mapper->findAllAttributesOfWhere('tag-name',['dev'=> 'edu',['name','!=','john']])

Check allowed where operators, (*29)

Where operators

Allowed where syntax., (*30)

Default: * key => value pair. Will be treated as ==, (*31)

 ['id' => 1,'name' => 'my name']

Custom: * != * !== * === * contains * containsCaseInsensitive, (*32)

[['name','!=','john'],['id','!=',7]]
[['name','contains','john']]

They can be combined, (*33)

['id' => 1,['name','!=','john']]

Replace tag names

You can easily replace any tag name of the xml for an easier access., (*34)

$mapper->replaceTagName(
    [
        'a10:author' => 'author',
        'a10:name' => 'name',
        'a10:updated' => 'updated'
    ]
);

The above snippet replaces all tags with names matching the keys and sets their values as new tag names. Also updates the underlying object based on the new xml., (*35)

Merge a new xml into the existing one

You can easily merge a new xml into the existing one. It sets it as child of the provided tag., (*36)

$mapper->mergeXML($newXml, 'desiredParentTag');

Wrap the current xml with a custom tag

$mapper->wrapWith('tagName');

Add attributes

$mapper-addAttributes(['attr1' => 'value1', 'attr2' => 'value2']);
or
$mapper-addAttributes(['attr1' => 'value1', 'attr2' => 'value2'], 'tagName');

Enjoy :), (*37)

The Versions

14/05 2018

dev-master

9999999-dev

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

14/05 2018

1.6.0

1.6.0.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

23/04 2018

1.5.3

1.5.3.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

23/04 2018

1.5.2

1.5.2.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

23/04 2018

1.5.1

1.5.1.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

23/04 2018

1.5.0

1.5.0.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

18/04 2018

1.4.0

1.4.0.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

12/04 2018

1.3.1

1.3.1.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

12/04 2018

1.3.0

1.3.0.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

11/04 2018

1.2.0

1.2.0.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

10/04 2018

1.1.0

1.1.0.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

07/04 2018

1.0.0

1.0.0.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

18/03 2018

0.1.0

0.1.0.0

XMLMapper for Laravel and PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

18/03 2018

dev-feature/laravel

dev-feature/laravel

Useful API to interact with XML data

  Sources   Download

MIT

The Requires

 

The Development Requires

by edujugon [Eduardo Marcos]

xml data

01/01 2018

0.0.3

0.0.3.0

Useful API to interact with XML data

  Sources   Download

MIT

The Development Requires

by edujugon [Eduardo Marcos]

xml data

27/12 2017

0.0.2

0.0.2.0

Useful API to interact with XML data

  Sources   Download

MIT

The Development Requires

by edujugon [Eduardo Marcos]

xml data

29/10 2017

0.0.1

0.0.1.0

Useful API to interact with XML data

  Sources   Download

MIT

The Development Requires

by edujugon [Eduardo Marcos]

xml data