[d24f17c] | 1 | var xml = require('../lib/xml');
|
---|
| 2 |
|
---|
| 3 | console.log('===== Example 1 ====');
|
---|
| 4 | var example1 = { url: 'http://www.google.com/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower' };
|
---|
| 5 | console.log(xml(example1));
|
---|
| 6 | //<url>http://www.google.com/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower</url>
|
---|
| 7 |
|
---|
| 8 | console.log('\n===== Example 2 ====');
|
---|
| 9 | var example2 = [ { url: { _attr: { hostname: 'www.google.com', path: '/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower' } } } ];
|
---|
| 10 | console.log(xml(example2));
|
---|
| 11 | //<url hostname="www.google.com" path="/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower"/>
|
---|
| 12 |
|
---|
| 13 | console.log('\n===== Example 3 ====');
|
---|
| 14 | var example3 = [ { toys: [ { toy: 'Transformers' } , { toy: 'GI Joe' }, { toy: 'He-man' } ] } ];
|
---|
| 15 | console.log(xml(example3));
|
---|
| 16 | //<toys><toy>Transformers</toy><toy>GI Joe</toy><toy>He-man</toy></toys>
|
---|
| 17 | console.log(xml(example3, { indent: true }));
|
---|
| 18 | /*
|
---|
| 19 | <toys>
|
---|
| 20 | <toy>Transformers</toy>
|
---|
| 21 | <toy>GI Joe</toy>
|
---|
| 22 | <toy>He-man</toy>
|
---|
| 23 | </toys>
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | console.log('\n===== Example 4 ====');
|
---|
| 27 | var example4 = [ { toys: [ { _attr: { decade: '80s', locale: 'US'} }, { toy: 'Transformers' } , { toy: 'GI Joe' }, { toy: 'He-man' } ] } ];
|
---|
| 28 | console.log(xml(example4, { indent: true }));
|
---|
| 29 | /*
|
---|
| 30 | <toys decade="80s" locale="US">
|
---|
| 31 | <toy>Transformers</toy>
|
---|
| 32 | <toy>GI Joe</toy>
|
---|
| 33 | <toy>He-man</toy>
|
---|
| 34 | </toys>
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | console.log('\n===== Example 5 ====');
|
---|
| 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>'} } ] } ] } ];
|
---|
| 39 | console.log(xml(example5, { indent: true, declaration: true }));
|
---|
| 40 | /*
|
---|
| 41 | <toys><toy>Transformers</toy><toy>GI Joe</toy><toy>He-man</toy></toys>
|
---|
| 42 | <toys>
|
---|
| 43 | <toy>Transformers</toy>
|
---|
| 44 | <toy>GI Joe</toy>
|
---|
| 45 | <toy>He-man</toy>
|
---|
| 46 | </toys>
|
---|
| 47 | <toys decade="80s" locale="US">
|
---|
| 48 | <toy>Transformers</toy>
|
---|
| 49 | <toy>GI Joe</toy>
|
---|
| 50 | <toy>He-man</toy>
|
---|
| 51 | </toys>
|
---|
| 52 | <toys decade="80s" locale="US">
|
---|
| 53 | <toy>Transformers</toy>
|
---|
| 54 | <toy knowing="half the battle">
|
---|
| 55 | GI Joe
|
---|
| 56 | </toy>
|
---|
| 57 | <toy>
|
---|
| 58 | <name>He-man</name>
|
---|
| 59 | <description><![CDATA[<strong>Master of the Universe!</strong>]]></description>
|
---|
| 60 | </toy>
|
---|
| 61 | </toys>
|
---|
| 62 | */
|
---|
| 63 |
|
---|
| 64 | console.log('\n===== Example 6 ====');
|
---|
| 65 | var elem = xml.Element({ _attr: { decade: '80s', locale: 'US'} });
|
---|
| 66 | var xmlStream = xml({ toys: elem }, { indent: true } );
|
---|
| 67 | xmlStream.on('data', function (chunk) {console.log("data:", chunk)});
|
---|
| 68 | elem.push({ toy: 'Transformers' });
|
---|
| 69 | elem.push({ toy: 'GI Joe' });
|
---|
| 70 | elem.push({ toy: [{name:'He-man'}] });
|
---|
| 71 | elem.close();
|
---|
| 72 |
|
---|
| 73 | /*
|
---|
| 74 | data: <toys decade="80s" locale="US">
|
---|
| 75 | data: <toy>Transformers</toy>
|
---|
| 76 | data: <toy>GI Joe</toy>
|
---|
| 77 | data: <toy>
|
---|
| 78 | <name>He-man</name>
|
---|
| 79 | </toy>
|
---|
| 80 | data: </toys>
|
---|
| 81 | */
|
---|