简体   繁体   English

使用node.js解析在线xml文档中的标签的问题

[英]Issues with parsing tags inside an online xml document with node.js

so I'm trying to create an application for the Google Assistant and the data for my application is stored in an online XML, however, I am not sure how I am supposed to extract the specific data that I require from the XML. 因此,我试图为Google助手创建一个应用程序,并且该应用程序的数据存储在在线XML中,但是,我不确定如何从XML中提取所需的特定数据。

I have tried to fix this by indexing the results of the XML parser however I receive either undefined errors or cannot read property errors. 我试图通过索引XML解析器的结果来解决此问题,但是我收到未定义的错误或无法读取属性错误。

 var eyes = require('eyes');
 var https = require('https');
 var fs = require('fs');
 var xml2js = require('xml2js');
 var parser = new xml2js.Parser({ attrkey: "ball"});

 parser.on('error', function(err) { console.log('Parser error', err); });

 var data = '';
 https.get('https://www.national-lottery.co.uk/results/euromillions/draw-history-full/xml', function(res) {
     if (res.statusCode >= 200 && res.statusCode < 400) {
       res.on('data', function(data_) { data += data_.toString(); });
       res.on('end', function() {
         console.log('data', data);
         parser.parseString(data, function(err, result) {
            toUse = result['draw-results']['game']['balls']['ball'][1];
            console.log(toUse);
            console.log('FINISHED', err, result);
         });
       });
     }
   });

I expect to receive an output of the first ball number called, however, I cannot get the data out other than printing the entire XML. 我希望收到第一个小球编号的输出,但是,除了打印整个XML外,我无法取出数据。

我得到的输出4的路径result['draw-results'].game[0].balls[0].ball[0]['_']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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