Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Loading XML results in Uncaught TypeError

$
0
0

Hi,

I'm trying to load several nodes from an XML file to variables, but in my code below I receive the following error in my console output:

[ERROR] : V8Exception: Exception occurred at alloy/controllers/index.js:170: Uncaught TypeError: Object #<NodeList> has no method 'getElementsByTagName'

This is the part of the function, where the error is generated:

var url = "http://tschmidt.nl/agf/xml/products/" + barcode + ".xml";
var xhr = Ti.Network.createHTTPClient();
xhr.open("GET", url);
 
xhr.onload = function(){
    var xml = this.responseXML.documentElement;
    var product = xml.getElementsByTagName("product");
    var image = product.getElementsByTagName("image").item(0).textContent;
 
    alert(image);
};
 
xhr.send();
productWindow.add(informationScroll);
productWindow.open();
What I'm trying to achieve with this code is loading a file from my webdomain, which is done using Scandit (the barcode scanner). When a barcode is scanned, this part of my function receives the barcode, combines it into an url, load the file and save the nodes from the XML into variables.

The line of the error I receive is the following:

var image = product.getElementsByTagName('image').item(0).textContent;

I've used the same method in the same project for creating a menu from XML nodes (in addition of a for loop) , which are working so I don't get why this isn't.


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>