Skip to content

Commit b53f55c

Browse files
committed
Update README
1 parent c406475 commit b53f55c

File tree

2 files changed

+207
-6
lines changed

2 files changed

+207
-6
lines changed

README.md

Lines changed: 199 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ array Xml2Array::convert(DOMDocument|SimpleXMLElement|string $inputXML)->toArray
4545

4646
> **Note:** The input XML can be one of types DOMDocument object, SimpleXMLElement object or well-formed XML string.
4747
48-
###### Example:
48+
###### Example 1 (Convert from XML string):
4949

5050
```php
5151
use Jackiedo\XmlArray\Xml2Array;
@@ -134,6 +134,200 @@ $array = [
134134
]
135135
```
136136

137+
###### Example 2 (Convert form XML object, as SimpleXMLElement):
138+
139+
```php
140+
use Jackiedo\XmlArray\Xml2Array;
141+
...
142+
143+
$xmlObject = simplexml_load_file('https://www.vietcombank.com.vn/ExchangeRates/ExrateXML.aspx');
144+
$array = Xml2Array::convert($xmlObject)->toArray();
145+
```
146+
147+
Result of piece of above code is:
148+
149+
```php
150+
$array = [
151+
"ExrateList" => [
152+
"DateTime" => "11/26/2018 1:56:20 PM",
153+
"Exrate" => [
154+
[
155+
"@attributes" => [
156+
"CurrencyCode" => "AUD",
157+
"CurrencyName" => "AUST.DOLLAR",
158+
"Buy" => "16724.09",
159+
"Transfer" => "16825.04",
160+
"Sell" => "17008.7"
161+
]
162+
],
163+
[
164+
"@attributes" => [
165+
"CurrencyCode" => "CAD",
166+
"CurrencyName" => "CANADIAN DOLLAR",
167+
"Buy" => "17412.21",
168+
"Transfer" => "17570.34",
169+
"Sell" => "17762.14"
170+
]
171+
],
172+
[
173+
"@attributes" => [
174+
"CurrencyCode" => "CHF",
175+
"CurrencyName" => "SWISS FRANCE",
176+
"Buy" => "23074.67",
177+
"Transfer" => "23237.33",
178+
"Sell" => "23538.02"
179+
]
180+
],
181+
[
182+
"@attributes" => [
183+
"CurrencyCode" => "DKK",
184+
"CurrencyName" => "DANISH KRONE",
185+
"Buy" => "0",
186+
"Transfer" => "3493.19",
187+
"Sell" => "3602.67"
188+
]
189+
],
190+
[
191+
"@attributes" => [
192+
"CurrencyCode" => "EUR",
193+
"CurrencyName" => "EURO",
194+
"Buy" => "26264.39",
195+
"Transfer" => "26343.42",
196+
"Sell" => "26736.61"
197+
]
198+
],
199+
[
200+
"@attributes" => [
201+
"CurrencyCode" => "GBP",
202+
"CurrencyName" => "BRITISH POUND",
203+
"Buy" => "29562.43",
204+
"Transfer" => "29770.83",
205+
"Sell" => "30035.68"
206+
]
207+
],
208+
[
209+
"@attributes" => [
210+
"CurrencyCode" => "HKD",
211+
"CurrencyName" => "HONGKONG DOLLAR",
212+
"Buy" => "2939.91",
213+
"Transfer" => "2960.63",
214+
"Sell" => "3004.95"
215+
]
216+
],
217+
[
218+
"@attributes" => [
219+
"CurrencyCode" => "INR",
220+
"CurrencyName" => "INDIAN RUPEE",
221+
"Buy" => "0",
222+
"Transfer" => "331.15",
223+
"Sell" => "344.15"
224+
]
225+
],
226+
[
227+
"@attributes" => [
228+
"CurrencyCode" => "JPY",
229+
"CurrencyName" => "JAPANESE YEN",
230+
"Buy" => "200.38",
231+
"Transfer" => "202.4",
232+
"Sell" => "207.05"
233+
]
234+
],
235+
[
236+
"@attributes" => [
237+
"CurrencyCode" => "KRW",
238+
"CurrencyName" => "SOUTH KOREAN WON",
239+
"Buy" => "19.07",
240+
"Transfer" => "20.07",
241+
"Sell" => "21.33"
242+
]
243+
],
244+
[
245+
"@attributes" => [
246+
"CurrencyCode" => "KWD",
247+
"CurrencyName" => "KUWAITI DINAR",
248+
"Buy" => "0",
249+
"Transfer" => "76615.44",
250+
"Sell" => "79621.23"
251+
]
252+
],
253+
[
254+
"@attributes" => [
255+
"CurrencyCode" => "MYR",
256+
"CurrencyName" => "MALAYSIAN RINGGIT",
257+
"Buy" => "0",
258+
"Transfer" => "5532.17",
259+
"Sell" => "5603.76"
260+
]
261+
],
262+
[
263+
"@attributes" => [
264+
"CurrencyCode" => "NOK",
265+
"CurrencyName" => "NORWEGIAN KRONER",
266+
"Buy" => "0",
267+
"Transfer" => "2674.72",
268+
"Sell" => "2758.55"
269+
]
270+
],
271+
[
272+
"@attributes" => [
273+
"CurrencyCode" => "RUB",
274+
"CurrencyName" => "RUSSIAN RUBLE",
275+
"Buy" => "0",
276+
"Transfer" => "349.9",
277+
"Sell" => "389.89"
278+
]
279+
],
280+
[
281+
"@attributes" => [
282+
"CurrencyCode" => "SAR",
283+
"CurrencyName" => "SAUDI RIAL",
284+
"Buy" => "0",
285+
"Transfer" => "6206.27",
286+
"Sell" => "6449.75"
287+
]
288+
],
289+
[
290+
"@attributes" => [
291+
"CurrencyCode" => "SEK",
292+
"CurrencyName" => "SWEDISH KRONA",
293+
"Buy" => "0",
294+
"Transfer" => "2536.35",
295+
"Sell" => "2600.19"
296+
]
297+
],
298+
[
299+
"@attributes" => [
300+
"CurrencyCode" => "SGD",
301+
"CurrencyName" => "SINGAPORE DOLLAR",
302+
"Buy" => "16775.66",
303+
"Transfer" => "16893.92",
304+
"Sell" => "17078.33"
305+
]
306+
],
307+
[
308+
"@attributes" => [
309+
"CurrencyCode" => "THB",
310+
"CurrencyName" => "THAI BAHT",
311+
"Buy" => "691.64",
312+
"Transfer" => "691.64",
313+
"Sell" => "720.49"
314+
]
315+
],
316+
[
317+
"@attributes" => [
318+
"CurrencyCode" => "USD",
319+
"CurrencyName" => "US DOLLAR",
320+
"Buy" => "23295",
321+
"Transfer" => "23295",
322+
"Sell" => "23385"
323+
]
324+
]
325+
],
326+
"Source" => "Joint Stock Commercial Bank for Foreign Trade of Vietnam - Vietcombank"
327+
]
328+
];
329+
```
330+
137331
### Convert XML to Json
138332

139333
###### Syntax:
@@ -142,7 +336,7 @@ $array = [
142336
string Xml2Array::convert(DOMDocument|SimpleXMLElement|string $inputXML)->toJson([int $options = 0]);
143337
```
144338

145-
###### Example:
339+
###### Example 3:
146340

147341
```php
148342
$jsonString = Xml2Array::convert($xmlString)->toJson(JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
@@ -156,13 +350,13 @@ $jsonString = Xml2Array::convert($xmlString)->toJson(JSON_UNESCAPED_UNICODE | JS
156350
string Array2Xml::convert(array $array)->toXml([bool $prettyOutput = false]);
157351
```
158352

159-
###### Example:
353+
###### Example 4:
160354

161355
```php
162356
use Jackiedo\XmlArray\Array2Xml;
163357
...
164358

165-
// We will use array from the result of above example as input for this example
359+
// We will use array from the result of first example as input for this example
166360
$xmlString = Array2Xml::convert($array)->toXml(true);
167361
```
168362

@@ -174,7 +368,7 @@ $xmlString = Array2Xml::convert($array)->toXml(true);
174368
DOMDocument Array2Xml::convert(array $array)->toDom();
175369
```
176370

177-
###### Example:
371+
###### Example 5:
178372

179373
```php
180374
$domObject = Array2Xml::convert($array)->toDom();

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
"keywords": [
55
"xml",
66
"array",
7-
"tools",
7+
"xml-to-array",
8+
"xmltoarray",
9+
"xml-2-array",
10+
"xml2array",
11+
"array-to-xml",
12+
"arraytoxml",
13+
"array-2-xml",
14+
"array2xml",
815
"convert",
916
"conversion"
1017
],

0 commit comments

Comments
 (0)