This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including @doodad-js/xml
with all npm
packages installed. Try it out:
require('@doodad-js/core').createRoot()
.then(root => {
return root.Doodad.Modules.load([
{
module: '@doodad-js/xml'
}
]);
})
.then(root => {
const xml = root.Doodad.Tools.Xml;
// NOTE: Random songs
return xml.parse("<songs><song><title>Another Me In Lack'ech</title><artist>Epica</artist></song><song><title>Silent Lucidity</title><artist>Queensryche</artist></song><song><title>One</title><artist>Metallica</artist></song></songs>");
}).then(doc => {
const getItemValue = function(items, name) {
return items.find(name)[0].getChildren().getAt(0).getValue();
};
for (let song of doc.getRoot().getChildren()) {
const items = song.getChildren();
console.log(getItemValue(items, 'title') + " from " + getItemValue(items, 'artist'));
};
}).catch(err => {
console.error(err);
});
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.