2017 © Pedro Peláez
 

library xml-parser

PHP Class that parses XML objects

image

jtrumbull/xml-parser

PHP Class that parses XML objects

  • Friday, March 18, 2016
  • by jtrumbull
  • Repository
  • 2 Watchers
  • 12 Stars
  • 2,798 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 10 Forks
  • 5 Open issues
  • 4 Versions
  • 20 % Grown

The README.md

XMLParser

I needed a quick way of outputting XML from an associative array on a few projects -this was the end result. I created this repository for later reference and fellow devs. At the time, It served it's purpose, however I am not actively developing this project -see the Contributing section., (*1)

Table of contents

Installation

  • composer require jtrumbull/xml-parser

Usage

header('Content-type: text/xml');

use XMLParser\XMLParser;

$data = array(
  'attr:status'=>'success',
  'Person'=>array(
    'attr:id'=>987654321,
    'First Name'=>'John',
    'Last Name'=>'Smith'
  ),
  'Address'=>array(
    'attr:'=>array(
      'geo-coded'=>TRUE,
      'lat'=>'0.0000',
      'lon'=>'-0.0000'
    ),
    'Street'=>'123 Main Street',
    'City'=>'Somewhere',
    'State'=>'DE',
    'Zip'=>'12345'
  ),
  'other'=>array(
    'key'=>'value',
    array('value1','value2','value3')
  )
);

$xml = XMLParser::encode( $data , 'response' );
echo $xml->asXML();

Will output:, (*2)

<response status="success">
  <person id="987654321">
    <first_name>John</first_name>
    <last_name>Smith</last_name>
  </person>
  <address geo-coded="TRUE" lat="0.0000" lon="-0.0000">
    <street>123 Main Street</street>
    <city>Somewhere</city>
    <state>DE</state>
    <zip>12345</zip>
  </address>
  <other>
    <key>value</key>
    <list>
      <item>value1</item>
      <item>value2</item>
      <item>value3</item>
    </list>
  </other>
</response>

Documentation

XMLParser\XMLParser::encode()

Syntax:, (*3)

SimpleXMLElement XMLParser::encode( mixed $data [, string $root] )

Returns: SimpleXMLElement, (*4)

XMLParser\XMLParser::decode()

Syntax:, (*5)

json XMLParser::decode( mixed $string )

Returns: json, (*6)

Contributing

Check out the issue tracker, if your issue or feature request has not addressed open a new issue. All pull requests are welcome., (*7)

Community

XML parser is distributed under the MIT License -see LICENSE.md, (*8)

The Versions

18/03 2016

dev-master

9999999-dev

PHP Class that parses XML objects

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-simplexml *

 

04/02 2016

v1.0.2

1.0.2.0

PHP Class that parses XML objects

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

04/02 2016

v1.0.1

1.0.1.0

PHP Class that parses XML objects

  Sources   Download

The Requires

  • php >=5.3.0

 

04/08 2015

v1.0.0

1.0.0.0

PHP Class that parses XML objects

  Sources   Download

The Requires

  • php >=5.3.0