javascript - XMLParser giving error ''Cannot set property value of undefined'' -


i working in react native app , trying execute piece of code

fetch('https://ad13.adfarm1.adition.com/banner?sid=3915124&wpt=x.xml') .then((response) => response.text()) .then((responsejson) => {     console.log("workingtillhere",responsejson)     xml_img = new xmlparser().parsefromstring(responsejson);    // assume xmltext contains example xml     console.log("parservideo,",xml_img); }) .catch((error) => {     console.log("parserex",error); }); 

i can see in console window

workingtillhere

but not execute xmlparser().parsefromstring(responsejson); , getting console log

parserex typeerror: cannot set property 'value' of undefined

same code works alright url link fetch('http://teststream.airtango.de/theo/vast.xml')

react-xml-parser not understand

<?xml version="1.0" encoding="utf-8"?> 

header. so, in general terms, could

fetch('https://ad13.adfarm1.adition.com/banner?sid=3915124&wpt=x.xml') .then((response) => response.text()) .then((xmltext) => {     // remove <?xml  ... etc header because react-xml-parser chokes on     if (xmltext.tolowercase().substr(0,5) == '<?xml') {         xmltext = xmltext.split(/\?>\r{0,1}\n{0,1}/).slice(1).join('?>\n');     }     console.log("workingtillhere",xmltext)     xml_img = new xmlparser().parsefromstring(xmltext);    // assume xmltext contains example xml     console.log("parservideo,",xml_img); }) .catch((error) => {     console.log("parserex",error); }); 

the above catch if first 5 characters <?xml ... may little naive on part. however, believe authors of react-xml-parser should handle <?xml ... ?> in code :p

looking @ source xmlparser, seems try handle it, fail

note, changing line 8 of xmlparse.js from

if (tags[i].indexof('?xml')) { 

to

if (tags[i].indexof('?xml') < 0 && tags[i].length > 0) { 

solves issue :p


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -