DOMParser https stream

Hi. I have a http Connection that needs to be open and listen to events in realtime. (http stream)
Today i use the reuest function to connect to the stream but my problem is that sometimes the xml comes in chunks and is not valid in the xml node. Now im trying to use DOMParser but can´t make this function to work. I am no expert on this but trying to learn :slight_smile:

What am i doing wrong? Is it possible to do this?

I think that you will need to watch the stream until you have a valid complete chunk, then you can parse it. So for example, if a chunk of output was wrapped in a <div class="thing">....</div> you would either need to wait for a </div> or better still, wait for another <div class="thing">, then you would know that you could parse the previous div.

But this is all very dependent on a good understanding of the stream. I don't think there is a generic solution.

Anyway, I've not tried anything like this so I might be completely wrong.

Hi. the End tag is always /event or /batch

this code works 70% of the times but sometimes the xml comes in three chunks

var request = global.get('request');

request({ 
    method: 'GET',
    uri: 'http://test:notrealpass@10.25.25.43:5004/a/eventexport?search_from_newest=true&end_date=keep&num_events=1
    gzip: true
},
function (ok, timeout, error, eof, quit) {
      console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'batch, event'))
      console.log('the decoded data is: ' + body)
     // console.log(response.headers['content-type' * text/xml])
    }
  )
  .on('data', function(data) {
    // decompressed data as it is received
    console.log('decompressed chunk arrived: ' + data)
    data = data.toString('utf8');
    node.send({payload: data});
})

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.