I am learning how to use Node. At this time, I have an XML file that looks like this:
sitemap.xml
<?xml version="1.0" encoding="utf-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <url> <loc>http://www.example.com</loc> <lastmod>2015-10-01</lastmod> <changefreq>monthly</changefreq> </url> <url> <loc>http://www.example.com/about</loc> <lastmod>2015-10-01</lastmod> <changefreq>never</changefreq> </url> <url> <loc>http://www.example.com/articles/tips-and-tricks</loc> <lastmod>2015-10-01</lastmod> <changefreq>never</changefreq> <article:title>Tips and Tricks</blog:title> <article:description>Learn some of the tips-and-tricks of the trade</article:description> </url> </urlset>
I am trying to load this XML in my Node application. When loading, I want to get only those url elements that include the use of <article: elements. I'm stuck at this time. Right now I am using XML2JS through the following:
var parser = new xml2js.Parser(); fs.readFile(__dirname + '/../public/sitemap.xml', function(err, data) { if (!err) { console.log(JSON.stringify(data)); } });
When the console.log statement is executed, I just see a bunch of numbers in the console window. Something like that:
{"type":"Buffer","data":[60,63,120, ...]}
What am I missing?
source share