pastuhov/php-xml2object

v1.0.0 2017-08-07 14:56 UTC

This package is not auto-updated.

Last update: 2024-03-19 14:36:59 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Total Downloads

Converts XML to object

Input:

<root>
    <detail detailid="3721899" formattedoem="90311-71001" manufacturer="TOYOTA">
        <properties>
            <property code="Name" detailpropertyid="6086730" locale="en_US" property="Наименование"/>
            <property property="Наименование" rate="5" value="カムシャフトセッティング オイル シール"/>
            <property rate="5" value="0.035 кг"/>
        </properties>
    </detail>
    <detail detailid="4445210" formattedoem="20621-71001" manufacturer="TOYOTA">
        <properties>
            <property code="Name" detailpropertyid="6086730" locale="en_US" property="Наименование"/>
            <property property="Наименование" rate="5" value="カムシャフトセッティング オイル シール"/>
        </properties>
    </detail>
</root>

Output:

{
    "_tagName": "root",
    "_childrenProperty": "children",
    "children": [
        {
            "_tagName": "detail",
            "_childrenProperty": "properties",
            "detailid": "3721899",
            "formattedoem": "90311-71001",
            "manufacturer": "TOYOTA",
            "properties": [
                {
                    "_tagName": "property",
                    "_childrenProperty": null,
                    "code": "Name",
                    "detailpropertyid": "6086730",
                    "locale": "en_US",
                    "property": "Наименование"
                },
                {
                    "_tagName": "property",
                    "_childrenProperty": null,
                    "property": "Наименование",
                    "rate": "5",
                    "value": "カムシャフトセッティング オイル シール"
                },
                {
                    "_tagName": "property",
                    "_childrenProperty": null,
                    "rate": "5",
                    "value": "0.035 кг"
                }
            ]
        },
        {
            "_tagName": "detail",
            "_childrenProperty": "properties",
            "detailid": "4445210",
            "formattedoem": "20621-71001",
            "manufacturer": "TOYOTA",
            "properties": [
                {
                    "_tagName": "property",
                    "_childrenProperty": null,
                    "code": "Name",
                    "detailpropertyid": "6086730",
                    "locale": "en_US",
                    "property": "Наименование"
                },
                {
                    "_tagName": "property",
                    "_childrenProperty": null,
                    "property": "Наименование",
                    "rate": "5",
                    "value": "カムシャフトセッティング オイル シール"
                }
            ]
        }
    ]
}

Features

  • converts desired tags to properties
  • fast
  • memory saving

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist pastuhov/php-xml2object

or add

"require-dev": {
    "pastuhov/php-xml2object": "~1.0.0"
    ...

to the require section of your composer.json file.

Usage

use pastuhov\xml2object\Parser;

$converter = new Parser();
$converter->xml = file_get_contents(__DIR__ . '/data/xml.xml');
$object = $converter->process();

Testing

./vendor/bin/phpunit

Security

If you discover any security related issues, please email pastukhov_k@sima-land.ru instead of using the issue tracker.