{"action":"created","issue":{"url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/235","labels_url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/235/labels{/name}","comments_url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/235/comments","events_url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/235/events","html_url":"https://github.com/Leonidas-from-XIV/node-xml2js/issues/235","id":106532589,"number":235,"title":"String is not parsed consistently ","user":{"login":"maisnamraju","id":2786378,"avatar_url":"https://avatars.githubusercontent.com/u/2786378?v=3","gravatar_id":"","url":"https://api.github.com/users/maisnamraju","html_url":"https://github.com/maisnamraju","followers_url":"https://api.github.com/users/maisnamraju/followers","following_url":"https://api.github.com/users/maisnamraju/following{/other_user}","gists_url":"https://api.github.com/users/maisnamraju/gists{/gist_id}","starred_url":"https://api.github.com/users/maisnamraju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maisnamraju/subscriptions","organizations_url":"https://api.github.com/users/maisnamraju/orgs","repos_url":"https://api.github.com/users/maisnamraju/repos","events_url":"https://api.github.com/users/maisnamraju/events{/privacy}","received_events_url":"https://api.github.com/users/maisnamraju/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-15T11:03:05Z","updated_at":"2015-09-15T14:26:22Z","closed_at":null,"body":"I tried parsing this website http://www.kapanlagi.com/feed/ and for some reason, the strings would parse at one instance and then if i run the script again, it would fail and return weird characters. \r\n\r\nI had to resolve to \r\n\r\n``` request('http://www.kapanlagi.com/feed/')\r\n    \t   .then(function(xml) {\r\n\r\n    \t   \tvar data = cheerio.load(xml).xml();\r\n    \t    \t    \r\n    \t  \tparseString(data,function(err, resp) {\r\n    \t  \t\t \t\r\n    \t  \t\t   var news = resp;\r\n    \t  \t\t   // check first if data is proper xml, if it is not then redo the request again \r\n\t\t    \t   if(err) {\r\n\t\t    \t   \t   request('http://www.kapanlagi.com/feed/')\t\r\n\t\t    \t   \t   \t.then(function(xml1) {\r\n\t\t    \t   \t   \t\tparseString(data,function(err1, resp1 ) {\r\n\t\t    \t   \t   \t\t\tnews = resp;\r\n\t\t    \t   \t   \t\t});\r\n\t\t    \t   \t   \t});\r\n\t\t    \t   \r\n\t\t    \t   }\r\n\r\n\t\t    \t   \tconsole.log(news);\r\n\r\n    \t  \t});\r\n\r\n   \t});\r\n``` \r\nto make it work, any ideas on what could be wrong \r\n\r\nmy error is \r\n\r\nLine: 0\r\nColumn: 1\r\nChar: some funny characters show up here\r\n"},"comment":{"url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/comments/140409625","html_url":"https://github.com/Leonidas-from-XIV/node-xml2js/issues/235#issuecomment-140409625","issue_url":"https://api.github.com/repos/Leonidas-from-XIV/node-xml2js/issues/235","id":140409625,"user":{"login":"tflanagan","id":5559820,"avatar_url":"https://avatars.githubusercontent.com/u/5559820?v=3","gravatar_id":"","url":"https://api.github.com/users/tflanagan","html_url":"https://github.com/tflanagan","followers_url":"https://api.github.com/users/tflanagan/followers","following_url":"https://api.github.com/users/tflanagan/following{/other_user}","gists_url":"https://api.github.com/users/tflanagan/gists{/gist_id}","starred_url":"https://api.github.com/users/tflanagan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tflanagan/subscriptions","organizations_url":"https://api.github.com/users/tflanagan/orgs","repos_url":"https://api.github.com/users/tflanagan/repos","events_url":"https://api.github.com/users/tflanagan/events{/privacy}","received_events_url":"https://api.github.com/users/tflanagan/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T14:26:22Z","updated_at":"2015-09-15T14:26:22Z","body":"I've queried them 1000 times without error.\r\n\r\nUse said code:\r\n```javascript\r\n'use strict';\r\n\r\nconst parseString = require('xml2js').parseString;\r\nconst http = require('http');\r\n\r\nconsole.time('test');\r\n\r\nlet i = 0, l = 1000, testXML;\r\n\r\n(testXML = (callback) => {\r\n\tlet callbackCalled = false, response = '';\r\n\r\n\tconsole.time('testXML');\r\n\tconsole.time('request');\r\n\r\n\tlet req = http.get('http://www.kapanlagi.com/feed/', (res) => {\r\n\t\tres.on('data', (chunk) => {\r\n\t\t\tresponse += chunk;\r\n\t\t});\r\n\r\n\t\tres.on('end', () => {\r\n\t\t\tconsole.timeEnd('request');\r\n\r\n\t\t\tfinGet();\r\n\t\t});\r\n\t});\r\n\r\n\treq.on('error', (err) => {\r\n\t\tconsole.timeEnd('request');\r\n\r\n\t\tif(!callbackCalled){\r\n\t\t\tcallbackCalled = true;\r\n\r\n\t\t\tcallback(err);\r\n\t\t}\r\n\t});\r\n\r\n\tlet finGet = () => {\r\n\t\tconsole.time('parseString');\r\n\t\tparseString(response, (err, data) => {\r\n\t\t\tconsole.timeEnd('parseString');\r\n\r\n\t\t\tif(err){\r\n\t\t\t\tif(!callbackCalled){\r\n\t\t\t\t\tcallbackCalled = true;\r\n\r\n\t\t\t\t\tcallback(err);\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\r\n\t\t\tconsole.timeEnd('testXML');\r\n\r\n\t\t\tif(i === l){\r\n\t\t\t\tcallback(null, 'success');\r\n\t\t\t}else{\r\n\t\t\t\t++i;\r\n\r\n\t\t\t\ttestXML();\r\n\t\t\t}\r\n\t\t});\r\n\t};\r\n})((err, results) => {\r\n\tconsole.timeEnd('test');\r\n\r\n\tif(err){\r\n\t\tconsole.error(err);\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\tconsole.log(results);\r\n});\r\n```\r\n\r\nLooking at your code, I see an error in your second parseString. You are referencing ```data``` where you should be referencing ```xml1```."}}