· 7 years ago · Dec 10, 2018, 05:34 AM
1# Example xml
2
3 <?xml version="1.0" encoding="UTF-8" ?>
4 <configuration>
5 <application id="test">
6 <platform id="vk">
7 <appId>123</appId>
8 <secretKey>secret</secretKey>
9 <packages>
10 <package id="vk0" price="100" points="3" />
11 <package id="vk1" price="500" points="20" />
12 <package id="vk2" price="1000" points="45" default="true" />
13 <package id="vk3" price="2500" points="130" />
14 <package id="vk4" price="5000" points="290" />
15 </packages>
16 </platform>
17 </application>
18</configuration>
19
20
21# Usage example
22
23 {Element, _} = xmerl_scan:string(binary_to_list(XmlData)),
24 Rules = {configuration, [],
25 [{application, [{id, to_atom}],
26 [{platform, [{id, to_atom}],
27 [
28 {appId, [], to_binary},
29 {secretKey, [], to_binary},
30 {packages, [], [
31 {package, [{id, to_atom},
32 {price, to_integer},
33 {points, to_integer},
34 {default, to_atom}], []}
35 ]}
36 ]
37 }]
38 }]
39 },
40 beenzaxml:process_xml(Element, Rules).
41
42# Will return easy-to-use deep proplist:
43
44 [{application,
45 [{platform,
46 [{appId,<<"123">>},
47 {secretKey,<<"secret">>},
48 {packages,
49 [{package,[{points,3},{price,100},{id,vk0}]},
50 {package,[{points,20},{price,500},{id,vk1}]},
51 {package,
52 [{default,true},
53 {points,45},
54 {price,1000},
55 {id,vk2}]},
56 {package,[{points,130},{price,2500},{id,vk3}]},
57 {package,[{points,290},{price,5000},{id,vk4}]}]},
58 {id,vk}]},
59 {id,test}]}]