Getting xml data
Moderator: General Moderators
Getting xml data
Hi, I would like to define a var, and then extract some xml data using that var (with AJAX). Pretty simple, but I cannot find any info on this. Any kind of help, like links or advice is greatly appreciated.
Re: Getting xml data
Are you saying you have a 'var' with url
and you want to load that xml file using AJAX and then get some data from it?
Code: Select all
var url = "/my_file.xml";Re: Getting xml data
Something like that, I figured it out by now. The problem was getting the exact xml tag. Thanks anyway...
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Getting xml data
Try...
If you're importing XML via AJAX you need to use importNode.
The above JavaScript will work in all browsers including IE.
Code: Select all
document.getElementById('test').getElementsByTagName('div')[0]The above JavaScript will work in all browsers including IE.
Re: Getting xml data
Thanks a lot, but neither of these 2 works in IE:
It reports an object error even though in Firefox both work?
Code: Select all
var xmlResponse = xmlHttp.responseXML;
if (!xmlResponse || !xmlResponse.documentElement)
throw("Invalid XML structure:\n" + xmlHttp.responseText);
xmlDocumentElement = xmlResponse.documentElement;
title=xmlDocumentElement.firstChild.data;
document.getElementById("myDivElement").innerHTML=title;Code: Select all
var xmlResponse = xmlHttp.responseXML;
if (!xmlResponse || !xmlResponse.documentElement)
throw("Invalid XML structure:\n" + xmlHttp.responseText);
var rootNodeName = xmlResponse.documentElement.nodeName;
if (rootNodeName == "parsererror") throw("Invalid XML structure");
xmlRoot = xmlResponse.documentElement;
titleArray = xmlRoot.getElementsByTagName("title");
var html = "";
for (var i=0; i<titleArray.length; i++)
html += titleArray.item(i).firstChild.data + "<br/>";
myDiv = document.getElementById("myDivElement");
myDiv.innerHTML = html;- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Getting xml data
IE8 developer tools, what error do you get and what line? Comment it out and start fixing it from there and remember to use object detection.
Re: Getting xml data
I have very little experience with IE developer tools, I don't have a clue where to look at, only thing I see is CSS and DOM stuff, no error reporting...
Re: Getting xml data
The microsoft script editor is probably the best way to debug JS on IE. If you have Office, it is included - http://blogs.msdn.com/ie/archive/2004/10/26/247912.aspx
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Getting xml data
If an error occurs you'll at least see a yellow triangle at the bottom left corner of IE8.
To access IE8's developer tools press F12 or you'll find it towards the bottom of the tools file menu.
In the developer tools click on the 'script' tag and then click on the 'Star Debugging' button. Sometimes it'll require you to reload the page which is fine.
If an error occurs (be it onload or long after onload has finished) it will automatically ALT+TAB you to the script debugger, show you the exact line where the error occurred, and give you the error message.
So far I'm really loving the developer tools in IE8. Granted I would never rely only on them...Firefox, Opera, and Safari's error consoles are all very useful (Firefox for stricter errors/warnings, Opera with trace-back, and Safari for mime errors come to mind off-hand).
To access IE8's developer tools press F12 or you'll find it towards the bottom of the tools file menu.
In the developer tools click on the 'script' tag and then click on the 'Star Debugging' button. Sometimes it'll require you to reload the page which is fine.
If an error occurs (be it onload or long after onload has finished) it will automatically ALT+TAB you to the script debugger, show you the exact line where the error occurred, and give you the error message.
So far I'm really loving the developer tools in IE8. Granted I would never rely only on them...Firefox, Opera, and Safari's error consoles are all very useful (Firefox for stricter errors/warnings, Opera with trace-back, and Safari for mime errors come to mind off-hand).
Re: Getting xml data
I click on "start debugging" - nothing happens. Not on html, not on js file. No triangle, when I load the page, an alert message pops up which says: "Can't connect to server: Type Error: Object doesn't support this property or method". In Firefox in works great! I appreciate your help Jab Creations.
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Getting xml data
No problem and try pytrin's suggestion, he's never led me wrong.
Ok you are likely dealing with a JScript issue...that is Microsoft doesn't support JavaScript...they use JScript...their own proprietary implementation of JavaScript...and they use different objects and methods in many instances. You generally have to do object detection. Here is an example...
To help you please copy the function containing the line where the error occurred in IE's developer toolbar and then we can help you adapt IE support.
Ok you are likely dealing with a JScript issue...that is Microsoft doesn't support JavaScript...they use JScript...their own proprietary implementation of JavaScript...and they use different objects and methods in many instances. You generally have to do object detection. Here is an example...
Code: Select all
if (window.addEventListener){ //standards compliant alert('JavaScript!');}else if (window.attachEvent){ //IE JScript proprietary implementationalert('JScript!');}