2
2
[ ![ Build Status] ( https://api.travis-ci.org/JackieDo/Xml-Array.svg?branch=master )] ( https://travis-ci.org/JackieDo/Xml-Array )
3
3
[ ![ Total Downloads] ( https://poser.pugx.org/jackiedo/xml-array/downloads )] ( https://packagist.org/packages/jackiedo/xml-array )
4
4
[ ![ Latest Stable Version] ( https://poser.pugx.org/jackiedo/xml-array/v/stable )] ( https://packagist.org/packages/jackiedo/xml-array )
5
- [ ![ Latest Unstable Version] ( https://poser.pugx.org/jackiedo/xml-array/v/unstable )] ( https://packagist.org/packages/jackiedo/xml-array )
6
5
[ ![ License] ( https://poser.pugx.org/jackiedo/xml-array/license )] ( https://packagist.org/packages/jackiedo/xml-array )
7
6
8
7
The conversion between xml and array becomes easier than ever. This package provides some very simple classes to convert XML to array and back.
@@ -15,38 +14,46 @@ The conversion between xml and array becomes easier than ever. This package prov
15
14
# Overview
16
15
Look at one of the following sessions to learn more about this package.
17
16
18
- * [ Installation] ( #installation )
19
- * [ Basic usage] ( #basic-usage )
17
+ - [ Xml-Array] ( #xml-array )
18
+ - [ Features of this package] ( #features-of-this-package )
19
+ - [ Overview] ( #overview )
20
+ - [ Installation] ( #installation )
21
+ - [ Basic usage] ( #basic-usage )
20
22
- [ Convert XML to array] ( #convert-xml-to-array )
21
23
- [ Convert XML to Json] ( #convert-xml-to-json )
22
24
- [ Convert array to XML] ( #convert-array-to-xml )
23
25
- [ Convert array to DOM] ( #convert-array-to-dom )
24
- * [ Advanced usage] ( #advanced-usage )
26
+ - [ Advanced usage] ( #advanced-usage )
25
27
- [ Set configuration] ( #set-configuration )
28
+ - [ Method 1] ( #method-1 )
29
+ - [ Method 2] ( #method-2 )
30
+ - [ Method 3] ( #method-3 )
26
31
- [ Get configuration] ( #get-configuration )
27
32
- [ Default configuration] ( #default-configuration )
28
- * [ License] ( #license )
33
+ - [ For Xml2Array] ( #for-xml2array )
34
+ - [ For Array2Xml] ( #for-array2xml )
35
+ - [ License] ( #license )
29
36
30
37
## Installation
31
38
You can install this package through [ Composer] ( https://getcomposer.org ) .
32
39
33
40
``` shell
34
- composer require jackiedo/xml-array
41
+ $ composer require jackiedo/xml-array
35
42
```
36
43
37
44
## Basic usage
38
45
39
46
### Convert XML to array
40
47
41
- ###### Syntax:
48
+ ** Syntax** :
42
49
43
50
```
44
51
array Xml2Array::convert(DOMDocument|SimpleXMLElement|string $inputXML)->toArray();
45
52
```
46
53
47
54
> ** Note:** The input XML can be one of types DOMDocument object, SimpleXMLElement object or well-formed XML string.
48
55
49
- ###### Example 1 (Convert from XML string):
56
+ ** Example 1** - _ (Convert from XML string)_ :
50
57
51
58
``` php
52
59
use Jackiedo\XmlArray\Xml2Array;
@@ -135,7 +142,7 @@ $array = [
135
142
]
136
143
```
137
144
138
- ###### Example 2 (Convert form XML object, such as SimpleXMLElement):
145
+ ** Example 2** - _ (Convert form XML object, such as SimpleXMLElement)_ :
139
146
140
147
``` php
141
148
use Jackiedo\XmlArray\Xml2Array;
@@ -331,27 +338,27 @@ $array = [
331
338
332
339
### Convert XML to Json
333
340
334
- ###### Syntax:
341
+ ** Syntax** :
335
342
336
343
```
337
344
string Xml2Array::convert(DOMDocument|SimpleXMLElement|string $inputXML)->toJson([int $options = 0]);
338
345
```
339
346
340
- ###### Example 3:
347
+ ** Example 3** :
341
348
342
349
``` php
343
350
$jsonString = Xml2Array::convert($xmlString)->toJson(JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
344
351
```
345
352
346
353
### Convert array to XML
347
354
348
- ###### Syntax:
355
+ ** Syntax** :
349
356
350
357
```
351
358
string Array2Xml::convert(array $array)->toXml([bool $prettyOutput = false]);
352
359
```
353
360
354
- ###### Example 4:
361
+ ** Example 4** :
355
362
356
363
``` php
357
364
use Jackiedo\XmlArray\Array2Xml;
@@ -363,13 +370,13 @@ $xmlString = Array2Xml::convert($array)->toXml(true);
363
370
364
371
### Convert array to DOM
365
372
366
- ###### Syntax:
373
+ ** Syntax** :
367
374
368
375
```
369
376
DOMDocument Array2Xml::convert(array $array)->toDom();
370
377
```
371
378
372
- ###### Example 5:
379
+ ** Example 5** :
373
380
374
381
``` php
375
382
$domObject = Array2Xml::convert($array)->toDom();
@@ -380,7 +387,7 @@ $domObject = Array2Xml::convert($array)->toDom();
380
387
### Set configuration
381
388
You can set configuration for conversion process with one of following methods:
382
389
383
- ###### Method 1:
390
+ #### Method 1
384
391
385
392
``` php
386
393
...
@@ -398,14 +405,14 @@ $xml = Array2Xml::convert($inputArray, $config)->toXml();
398
405
399
406
> ** Note** : Configuration is an array of parameters. For more details, see section [ Default configuration] ( #default-configuration ) .
400
407
401
- ###### Method 2:
408
+ #### Method 2
402
409
403
410
``` php
404
411
$converter = new Xml2Array($config);
405
412
$array = $converter->convertFrom($inputXml)->toArray();
406
413
```
407
414
408
- ###### Method 3:
415
+ #### Method 3
409
416
410
417
``` php
411
418
$converter = new Xml2Array;
@@ -421,7 +428,7 @@ $config = $converter->getConfig();
421
428
422
429
### Default configuration
423
430
424
- ###### For Xml2Array
431
+ #### For Xml2Array
425
432
426
433
``` php
427
434
$defaultConfig = [
@@ -434,7 +441,7 @@ $defaultConfig = [
434
441
];
435
442
```
436
443
437
- ###### For Array2Xml
444
+ #### For Array2Xml
438
445
439
446
``` php
440
447
$defaultConfig = [
@@ -447,5 +454,5 @@ $defaultConfig = [
447
454
];
448
455
```
449
456
450
- ## License
457
+ # License
451
458
[ MIT] ( LICENSE ) © Jackie Do
0 commit comments