Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7416585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:31:37+00:00 2026-05-29T07:31:37+00:00

Ok so I have attempted to use multiple XML libraries that NodeJS have to

  • 0

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.

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.

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.

Current 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 > pubDate', function(element) {

    element.$text = element.$text;

  }); 


  xml.on('data', function(data) {
    process.stdout.write(data);
  });
});

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:31:38+00:00Added an answer on May 29, 2026 at 7:31 am

    There is a byte order mark before the <?xml tag, which xml-stream trips up on a bit and stops it from being able to read the encoding in the tag. That means you need to provide it yourself.

    Instead of this:

    response.setEncoding('utf8');
    var xml = new XmlStream(response);
    

    Just do this:

    response.setEncoding('utf8');
    var xml = new XmlStream(response, 'utf8');
    

    And really, setting the encoding on the stream is optional.

    var xml = new XmlStream(response, 'utf8');
    

    works just fine.

    More info here: http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8

    If you look at the buffer emitted from response rather that xml, the buffer starts with

    <Buffer ef bb bf 3c 3f 78 6d ...>
    

    The first 3 bytes are the byte order mark for utf8, and afterwards you have the start of the tag. xml-stream expects the <?xml tag to only have whitespace between it and the start of the file, but byte order marks don’t count as whitespace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that gets rolled out in multiple countries. There will be
I have attempted to create a function that will replace multiple regular expression values
I want to have multiple PyPI servers in my ~/.pypirc file so I can
I have attempted to use this CSS to set the width of my form
Can Unicode characters be encoded and decoded with Base64 ? I have attempted to
I have a project w/ multiple apps. I am attempting to use the dumpdata
I have a flash upload component I want to use to upload multiple files.
I have a basic PDF file that I has 5 different blank content areas
I have multiple SharePoint web parts that needs to access Reporting service 2008 which
I have created my first asp.net UserControl that I will use in several places

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.