javascript - Reading XML file in Node.js -


i'm learning how use node. @ time, have xml file looks 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 , tricks</blog:title>     <article:description>learn of tips-and-tricks of trade</article:description>   </url> </urlset> 

i trying load xml in node app. when loaded, want url elements include use of <article: elements. @ time, i'm stuck though. right now, i'm using xml2js via following:

var parser = new xml2js.parser(); fs.readfile(__dirname + '/../public/sitemap.xml', function(err, data) {     if (!err) {         console.log(json.stringify(data));     } }); 

when console.log statement executed, see bunch of numbers in console window. this:

{"type":"buffer","data":[60,63,120, ...]} 

what missing?

from the documentation.

the callback passed 2 arguments (err, data), data contents of file.

if no encoding specified, raw buffer returned.

if options string, specifies encoding. example:

fs.readfile('/etc/passwd', 'utf8', callback); 

you didn't specify encoding, raw buffer.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -