1
1
var xml = require ( '../lib/xml' ) ;
2
2
3
-
3
+ console . log ( '===== Example 1 ====' ) ;
4
4
var example1 = { url : 'http://www.google.com/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower' } ;
5
5
console . log ( xml ( example1 ) ) ;
6
6
//<url>http://www.google.com/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower</url>
7
7
8
+ console . log ( '\n===== Example 2 ====' ) ;
8
9
var example2 = [ { url : { _attr : { hostname : 'www.google.com' , path : '/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower' } } } ] ;
9
10
console . log ( xml ( example2 ) ) ;
10
11
//<url hostname="www.google.com" path="/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower"/>
11
12
13
+ console . log ( '\n===== Example 3 ====' ) ;
12
14
var example3 = [ { toys : [ { toy : 'Transformers' } , { toy : 'GI Joe' } , { toy : 'He-man' } ] } ] ;
13
15
console . log ( xml ( example3 ) ) ;
14
16
//<toys><toy>Transformers</toy><toy>GI Joe</toy><toy>He-man</toy></toys>
15
- console . log ( xml ( example3 , true ) ) ;
17
+ console . log ( xml ( example3 , { indent : true } ) ) ;
16
18
/*
17
19
<toys>
18
20
<toy>Transformers</toy>
@@ -21,8 +23,9 @@ console.log(xml(example3, true));
21
23
</toys>
22
24
*/
23
25
26
+ console . log ( '\n===== Example 4 ====' ) ;
24
27
var example4 = [ { toys : [ { _attr : { decade : '80s' , locale : 'US' } } , { toy : 'Transformers' } , { toy : 'GI Joe' } , { toy : 'He-man' } ] } ] ;
25
- console . log ( xml ( example4 , true ) ) ;
28
+ console . log ( xml ( example4 , { indent : true } ) ) ;
26
29
/*
27
30
<toys decade="80s" locale="US">
28
31
<toy>Transformers</toy>
@@ -31,8 +34,9 @@ console.log(xml(example4, true));
31
34
</toys>
32
35
*/
33
36
37
+ console . log ( '\n===== Example 5 ====' ) ;
34
38
var example5 = [ { toys : [ { _attr : { decade : '80s' , locale : 'US' } } , { toy : 'Transformers' } , { toy : [ { _attr : { knowing : 'half the battle' } } , 'GI Joe' ] } , { toy : [ { name : 'He-man' } , { description : { _cdata : '<strong>Master of the Universe!</strong>' } } ] } ] } ] ;
35
- console . log ( xml ( example5 , true ) ) ;
39
+ console . log ( xml ( example5 , { indent : true , declaration : true } ) ) ;
36
40
/*
37
41
<toys><toy>Transformers</toy><toy>GI Joe</toy><toy>He-man</toy></toys>
38
42
<toys>
@@ -57,8 +61,9 @@ console.log(xml(example5, true));
57
61
</toys>
58
62
*/
59
63
64
+ console . log ( '\n===== Example 6 ====' ) ;
60
65
var elem = xml . Element ( { _attr : { decade : '80s' , locale : 'US' } } ) ;
61
- var xmlStream = xml ( { toys : elem } , true ) ;
66
+ var xmlStream = xml ( { toys : elem } , { indent : true } ) ;
62
67
xmlStream . on ( 'data' , function ( chunk ) { console . log ( "data:" , chunk ) } ) ;
63
68
elem . push ( { toy : 'Transformers' } ) ;
64
69
elem . push ( { toy : 'GI Joe' } ) ;
0 commit comments