var xml = require('../lib/xml');
console.log('===== Example 1 ====');
var example1 = { url: 'http://www.google.com/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower' };
console.log(xml(example1));
//http://www.google.com/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower
console.log('\n===== Example 2 ====');
var example2 = [ { url: { _attr: { hostname: 'www.google.com', path: '/search?aq=f&sourceid=chrome&ie=UTF-8&q=opower' } } } ];
console.log(xml(example2));
//
console.log('\n===== Example 3 ====');
var example3 = [ { toys: [ { toy: 'Transformers' } , { toy: 'GI Joe' }, { toy: 'He-man' } ] } ];
console.log(xml(example3));
//TransformersGI JoeHe-man
console.log(xml(example3, { indent: true }));
/*
Transformers
GI Joe
He-man
*/
console.log('\n===== Example 4 ====');
var example4 = [ { toys: [ { _attr: { decade: '80s', locale: 'US'} }, { toy: 'Transformers' } , { toy: 'GI Joe' }, { toy: 'He-man' } ] } ];
console.log(xml(example4, { indent: true }));
/*
Transformers
GI Joe
He-man
*/
console.log('\n===== Example 5 ====');
var example5 = [ { toys: [ { _attr: { decade: '80s', locale: 'US'} }, { toy: 'Transformers' } , { toy: [ { _attr: { knowing: 'half the battle' } }, 'GI Joe'] }, { toy: [ { name: 'He-man' }, { description: { _cdata: 'Master of the Universe!'} } ] } ] } ];
console.log(xml(example5, { indent: true, declaration: true }));
/*
TransformersGI JoeHe-man
Transformers
GI Joe
He-man
Transformers
GI Joe
He-man
Transformers
GI Joe
He-man
Master of the Universe!]]>
*/
console.log('\n===== Example 6 ====');
var elem = xml.Element({ _attr: { decade: '80s', locale: 'US'} });
var xmlStream = xml({ toys: elem }, { indent: true } );
xmlStream.on('data', function (chunk) {console.log("data:", chunk)});
elem.push({ toy: 'Transformers' });
elem.push({ toy: 'GI Joe' });
elem.push({ toy: [{name:'He-man'}] });
elem.close();
/*
data:
data: Transformers
data: GI Joe
data:
He-man
data:
*/