简体   繁体   中英

Result from xml2js

I'm trying to parse xml after a request.

var fs = require('fs'),
    parseString = require('xml2js').parseString,
    request = require('request');


    request('http://www.stands4.com/services/v2/quotes.php?uid=123&tokenid=123&searchtype=RANDOM', function (error, response, body) {
       if (!error && response.statusCode == 200) {
           parseString(body, function (err, result) {
               console.dir(result);
        });

     }
})

XML

<?xml version="1.0" encoding="UTF-8"?>
<results><result><quote>Some Text</quote><author>Name</author></result></results>

Returns

{ results: { result: [ [Object] ] } }

Why it isn't returning the correct format?

{ results: { result: [ [Object] ] } }

is the result of console.dir , not the actual value of result.

if you want to know what is the result,try

console.log(JSON.stringify(result));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM