Note that there are some explanatory texts on larger screens.

plurals
  1. PORead XML hosted file with NodeJS
    primarykey
    data
    text
    <p>Ok so I have attempted to use multiple XML libraries that NodeJS have to offer and I can't seem to work out how to have an NodeJS read the XML file from a website. </p> <p>I can pull the file using http.request, http.get and all of that but then to have NodeJS be able to actually do anything with the data in the XML file is another story.</p> <p>I'm sure I must be missing something as when ever I turn the XML to JS with xml-stream; it can not use it from a website; my code runs when I host the file however I am using an api and they only use XML.</p> <p>Current code: </p> <pre><code> var http = require('http'); var XmlStream = require('xml-stream'); var options = { host: 'cloud.tfl.gov.uk', path: '/TrackerNet/LineStatus'}; var twitter = { host: 'api.twitter.com', path: '/1/statuses/user_timeline.rss?screen_name=nwhite89'} var request = http.get(options).on('response', function(response) { response.setEncoding('utf8'); var xml = new XmlStream(response); xml.on('updateElement: item', function(item) { item.title = item.title.match(/^[^:]+/)[0] + ' on ' + item.pubDate.replace(/ +[0-9]{4}/, ''); }); xml.on('text: item &gt; pubDate', function(element) { element.$text = element.$text; }); xml.on('data', function(data) { process.stdout.write(data); }); }); </code></pre> <p>What I don't understand is using Twitter works fine outputs at xml.on("data") part however using options (cloud.tfl.gov.uk) nothing outputs even if I put console.log("hi") inside the data function it dosn't get executed.</p> <p>I know that the url is correct outputting console.log(xml) or console.log(response) after creating the variable xml outputs that it has connected. Any help would be greatly appreciated with this I have been stuck on this for a good 2 days now. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload