Page 1 of 1

Getting xml data

Posted: Mon Jul 20, 2009 4:06 am
by LDusan
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

Posted: Mon Jul 20, 2009 11:19 am
by kaszu
Are you saying you have a 'var' with url

Code: Select all

var url = "/my_file.xml";
and you want to load that xml file using AJAX and then get some data from it?

Re: Getting xml data

Posted: Mon Jul 20, 2009 11:27 am
by LDusan
Something like that, I figured it out by now. The problem was getting the exact xml tag. Thanks anyway...

Re: Getting xml data

Posted: Thu Jul 23, 2009 6:39 am
by JAB Creations
Try...

Code: Select all

document.getElementById('test').getElementsByTagName('div')[0]
If you're importing XML via AJAX you need to use importNode.

The above JavaScript will work in all browsers including IE. :)

Re: Getting xml data

Posted: Sun Jul 26, 2009 3:27 pm
by LDusan
Thanks a lot, but neither of these 2 works in IE:

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;
It reports an object error even though in Firefox both work?

Re: Getting xml data

Posted: Fri Jul 31, 2009 9:10 am
by JAB Creations
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

Posted: Sat Aug 01, 2009 6:13 pm
by LDusan
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

Posted: Sat Aug 01, 2009 6:20 pm
by Eran
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

Re: Getting xml data

Posted: Sat Aug 01, 2009 6:29 pm
by JAB Creations
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).

Re: Getting xml data

Posted: Sat Aug 01, 2009 6:47 pm
by LDusan
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.

Re: Getting xml data

Posted: Sat Aug 01, 2009 7:18 pm
by JAB Creations
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...

Code: Select all

if (window.addEventListener){ //standards compliant alert('JavaScript!');}else if (window.attachEvent){ //IE JScript proprietary implementationalert('JScript!');}
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.