![]() |
Help with reading a XML file
I'm using javascript code (which I got from w3schools.com) to get elements from a xml file, but something goes wrong after the xml has been read. Please help me to find the error:
Code:
xmlhttp=new XMLHttpRequest();document.write("-1");My xml document is this: Code:
<?xml version="1.0" encoding="ISO-8859-1"?>Code:
text=xmlDoc.getElementsByTagName("nombre")[0].childNodes[0].nodeValue;Sorry if this thread doesn't belong here but I didn't know if it goes in AJAX, XML or Javascript, please move it at will. |
I think it might have to do with your XMLHttpRequest.open() call - the third argument set to true indicates asynchronous calls. Which means when you try to read it, you haven't got the full document yet.
Please don't try to convert to synchronous XMLHttpRequests - they're not very nice. Instead, look into event handlers that XHR's provide. |
"http://www.myurl.com/control/xml/myproducts2.xml" does not yield the xml file. So I loaded the file into my main area where the file that will read it lives and just called it as a file. Here is some code to get you going.
Code:
<!DOCTYPE html> |
Sunfighter, just a question: are you aware that myurl.com is a fictitious url? I'm not an experienced coder, so I'm going to try that code and let you know.
|
| All times are GMT +1. The time now is 10:37 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.