var xmlreader = require('./xmlreader'); var someXml = '' + 'This is some other content' + 'James May' + '' + 'Sam Decrock' + 'Belgium' + '' + 'Jack Johnsen' + '' + 'Some great game' + 'Some other great game' + '' + '' + '<![CDATA[Some text between CDATA tags]]>' + '' + 'These are some notes' + '' xmlreader.read(someXml, function (err, res){ if(err) return console.log(err); // use .text() to get the content of a node: console.log( res.response.text() ); // use .attributes() to get the attributes of a node: console.log( res.response.attributes().shop ); console.log(""); // using the .count() and the .at() function, you can loop through nodes with the same name: for(var i = 0; i < res.response.who.count(); i++){ console.log( res.response.who.at(i).text() ); } console.log(""); // you can also use .each() to loop through the nodes of the same name: res.response.who.each(function (i, who){ console.log( who.text() ); }); console.log(""); console.log( res.response.who.at(1).text() ) ; console.log( res.response.who.at(1).location.text() ); // you can also use .at() to get to nodes where there's only one of them: console.log( res.response.note.at(0).text() ); console.log(""); // or loop through them as if they were a series of nodes with the same name: res.response.note.each(function (i, note){ console.log( note.text() ); }); console.log(""); console.log( res.response.title.text() ); console.log(""); // you can also get the parent of a node using .parent(): console.log( res.response.who.at(1).parent().attributes().id ) ; });