2017 © Pedro PelĂĄez
 

library xml2struct

Simple lib to convert a xml file into a tree structure of nodes, an array structure or a json string.

image

jitesoft/xml2struct

Simple lib to convert a xml file into a tree structure of nodes, an array structure or a json string.

  • Thursday, September 14, 2017
  • by JiteSoft
  • Repository
  • 2 Watchers
  • 1 Stars
  • 54 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 2 % Grown

The README.md

Build Status, (*1)

Build Status, (*2)

Dependency Status, (*3)

XML2Struct

XML can be a pain... Sometimes its a lot more handy to work with a tree structure or even json or an array!
This package was created to ease testing with xml files, so that, instead of going through a lengthy DOMElement test case or even just string-matching the xml right away, one could convert the xml into a more easily handled structure.
Thus XML2Struct was born., (*4)

Usage:

Install package through composer:, (*5)

composer require jitesoft/xml2struct

The parser is quite simple to use, all that is needed is to create a new parser object and call its parse method supplying the xml you want parsed as a string:, (*6)

$parser = new Jitesoft\XML\Parser();
// Node tree!
$out    = $parser->parse(file_get_contents('myxmlfile.xml'));
// Json string!
$json   = json_encode($out);
// Array!
$array  = $out->toArray();

For more in-depth examples, check the examples folder., (*7)

The object returned is a Jitesoft\XML\Node structure.
The structure have the following fields defined:, (*8)

name:       string                  default: ""
content:    string                  default: ""
attributes: array ([key => value])  default: []
children:   array ([Node])          default: []

When converting a node to an array or a json string, the properties or keys will be named the same as the Nodes fields. The keys will always be there, even if there is no value from the xml, if no parsed value, it will be the default value stated above.., (*9)

Changes

2.0

  • Removed OutType on parsing. Instead use Node::toArray and json_encode($node).
  • Removed Node::toString override. Dump as json if wanted as json.

Issues and PR's.

Any issues found should be reported in this repository issue tracker, issues will be fixed when possible.
Pull requests will be accepted, but please try to follow the general code-style!, (*10)

License

MIT License

Copyright (c) 2017 Jitesoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

The Versions

14/09 2017

dev-develop

dev-develop https://github.com/jitesoft/php-xml2array

Simple lib to convert a xml file into a tree structure of nodes, an array structure or a json string.

  Sources   Download

MIT

The Requires

 

The Development Requires

xml array convert parsing

14/09 2017

dev-master

9999999-dev https://github.com/jitesoft/php-xml2array

Simple lib to convert a xml file into a tree structure of nodes, an array structure or a json string.

  Sources   Download

MIT

The Requires

 

The Development Requires

xml array convert parsing

14/09 2017

2.0.0

2.0.0.0 https://github.com/jitesoft/php-xml2array

Simple lib to convert a xml file into a tree structure of nodes, an array structure or a json string.

  Sources   Download

MIT

The Requires

 

The Development Requires

xml array convert parsing

26/08 2017

1.2.0

1.2.0.0 https://github.com/jitesoft/php-xml2array

Simple lib to convert a xml file into a tree structure of nodes, an array structure or a json string.

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

xml array convert parsing

09/03 2017

1.1.0

1.1.0.0 https://github.com/jitesoft/php-xml2array

Simple lib to convert a xml file into a tree structure of nodes, an array structure or a json string.

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

xml array convert parsing

03/03 2017

1.0.0

1.0.0.0 https://github.com/jitesoft/php-xml2array

Simple lib to convert a xml file into a array of Elements.

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

xml array parsing