<commit_before>[![Build Status](https://img.shields.io/travis/jitesoft/php-xml2array/master.svg?label=master)](https://travis-ci.org/jitesoft/php-datastructures)  

[![Build Status](https://img.shields.io/travis/jitesoft/php-xml2array/develop.svg?label=develop)](https://travis-ci.org/jitesoft/php-datastructures)

[![Dependency Status](https://gemnasium.com/badges/github.com/jitesoft/php-xml2array.svg)](https://gemnasium.com/github.com/jitesoft/php-datastructures)

# XML2Struct

XML can be a pain... Sometimes its a lot more handy to work with a tree structure, 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.

## Usage:

Install package through composer:
```
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:
```php
$parser = new Jitesoft\XML\Parser();
// Node tree!
$out    = $parser->parse(file_get_contents('myxmlfile.xml'));
// Json string!
$out    = $parser->parse(file_get_contents('myxmlfile.xml'), Parser::OUT_TYPE_JSON);
// Array!
$out    = $parser->parse(file_get_contents('myxmlfile.xml'), Parser::OUT_TYPE_ARRAY);
```

The object returned by the default parse out-type is a `Jitesoft\XML\Node` structure.  
The structure have the following fields defined:
```
name:       string                  default: ""
content:    string                  default: ""
attributes: array ([key => value])  default: []
children:   array ([Node])          default: []
```
The structure is also what either of the other out-types will export.
The values will always be set to something, even if there is no value from the xml.  

Its possible to convert the node structure returned from the default out-type, so no need to parse a xml file multiple times
if a new out-type is wanted:

```php
$node->toArray();
$node->toJson();
```

The node also have its `__toString` method to return the node-tree as a json string. 

## 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! 
<commit_msg>Readme fix.<commit_after>[![Build Status](https://img.shields.io/travis/jitesoft/php-xml2array/master.svg?label=master)](https://travis-ci.org/jitesoft/php-xml2array)  

[![Build Status](https://img.shields.io/travis/jitesoft/php-xml2array/develop.svg?label=develop)](https://travis-ci.org/jitesoft/php-xml2array)

[![Dependency Status](https://gemnasium.com/badges/github.com/jitesoft/php-xml2array.svg)](https://gemnasium.com/github.com/jitesoft/php-xml2array)

# XML2Struct

XML can be a pain... Sometimes its a lot more handy to work with a tree structure, 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.

## Usage:

Install package through composer:
```
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:
```php
$parser = new Jitesoft\XML\Parser();
// Node tree!
$out    = $parser->parse(file_get_contents('myxmlfile.xml'));
// Json string!
$out    = $parser->parse(file_get_contents('myxmlfile.xml'), Parser::OUT_TYPE_JSON);
// Array!
$out    = $parser->parse(file_get_contents('myxmlfile.xml'), Parser::OUT_TYPE_ARRAY);
```

The object returned by the default parse out-type is a `Jitesoft\XML\Node` structure.  
The structure have the following fields defined:
```
name:       string                  default: ""
content:    string                  default: ""
attributes: array ([key => value])  default: []
children:   array ([Node])          default: []
```
The structure is also what either of the other out-types will export.
The values will always be set to something, even if there is no value from the xml.  

Its possible to convert the node structure returned from the default out-type, so no need to parse a xml file multiple times
if a new out-type is wanted:

```php
$node->toArray();
$node->toJson();
```

The node also have its `__toString` method to return the node-tree as a json string. 

## 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! 

{'fraction_non_alphanumeric': 0.10922981622960974, 'fraction_numerical': 0.003097253768325418, 'mean_word_length': 4.125925925925926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 35}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7090695', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1405, 'n_words': 543}