Solved

Parsing XML in IE and Firefox

Posted on 2009-06-30
2
817 Views
Last Modified: 2012-05-07
Hi Experts,
Here is what I think is a simple question but I can't seem to figure it out.
I want to parse a really simple xml file known as test.xml and display the fields in a span on my browser page it works great in Firefox but returns blank in Internet Explorer 8.
I would appeciate it if you can find out what it is that is blocking this thing from displaying the parsed fields.
Here is the simple xml File:

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

<rss version="2.0">

<channel>

<line01> </line01>

<line02>'Ciih½VÓœ</line02>

<line03> </line03>

<line04>2009t313÷</line04>

<line05> </line05>

<line06> </line06>

<line07>xÐpW:</line07>

<line08>12-24-26-36-42</line08>

<line09> </line09>

<line10> </line10>

<line11>xÐ:</line11>

<line12>1-4</line12>

<line13> </line13>

<line14> </line14>

<line15>xÐ:</line15>

<line16>1-4</line16>

<line17> </line17>

<line18> </line18>

<line19>
!„'V:</line19>

<line20>16.009.560,30 ¬</line20>

<line21> </line21>

<line22> </line22>

<line23>¨Â ½V†?</line23>

<line24>'2'„ih½V!</line24>

<line25> </line25>

<line26> </line26>

<line27>!V</line27>

<line28>2009t320÷</line28>

<line29> </line29>

<line30> </line30>

<line31>!„'V:</line31>

<line32>29,000,000 Euros!</line32>

<line33> </line33>

</channel>

</rss>
 

Here is the Header Javascript:

<script type="text/javascript">

function loadXMLDoc(dname) 

{

var xmlDoc;

if (window.XMLHttpRequest)

  {

  xmlDoc=new window.XMLHttpRequest();

  xmlDoc.open("GET",dname,false);

  xmlDoc.send("");

  return xmlDoc.responseXML;

  }

// IE 5 and IE 6

else if (ActiveXObject("Microsoft.XMLDOM"))

  {

  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

  xmlDoc.async=false;

  xmlDoc.load(dname);

  return xmlDoc;

  }

alert("Error loading document");

return null;

}

</script>
 

Here sre the HTML Fields and the inline Javascript:
 

            <div style="font-size:11px; text-align:center; font-weight: bold; width: 160px;">

            <p><span id="line01"></span><br />

            <span id="line02"></span><br />

            <span id="line03"></span><br />

            <span id="line04"></span><br />

            <span id="line05"></span><br />

            <span id="line06"></span><br />

            <span id="line07"></span><br />

            <span id="line08"></span><br />

            <span id="line09"></span><br />

            <span id="line10"></span><br />

            <span id="line11"></span><br />

            <span id="line12"></span><br />

            <span id="line13"></span><br />

            <span id="line14"></span><br />

            <span id="line15"></span><br />

            <span id="line16"></span><br />

            <span id="line17"></span><br />

            <span id="line18"></span><br />

            <span id="line19"></span><br />

            <span id="line20"></span><br />

            <span id="line21"></span><br />

            <span id="line22"></span><br />

            <span id="line23"></span><br />

            <span id="line24"></span><br />

            <span id="line25"></span><br />

            <span id="line26"></span><br />

            <span id="line27"></span><br />

            <span id="line28"></span><br />

            <span id="line29"></span><br />

            <span id="line30"></span><br />

            <span id="line31"></span><br />

            <span id="line32"></span><br />

            <span id="line33"></span></p>

           

            <script type="text/javascript">

				xmlDoc=loadXMLDoc("feeds/test.xml");

				document.getElementById("line01").innerHTML=xmlDoc.getElementsByTagName("line01")[0].childNodes[0].nodeValue;

				document.getElementById("line02").innerHTML=xmlDoc.getElementsByTagName("line02")[0].childNodes[0].nodeValue;

				document.getElementById("line03").innerHTML=xmlDoc.getElementsByTagName("line03")[0].childNodes[0].nodeValue;

				document.getElementById("line04").innerHTML=xmlDoc.getElementsByTagName("line04")[0].childNodes[0].nodeValue;

				document.getElementById("line05").innerHTML=xmlDoc.getElementsByTagName("line05")[0].childNodes[0].nodeValue;

				document.getElementById("line06").innerHTML=xmlDoc.getElementsByTagName("line06")[0].childNodes[0].nodeValue;

				document.getElementById("line07").innerHTML=xmlDoc.getElementsByTagName("line07")[0].childNodes[0].nodeValue;

				document.getElementById("line08").innerHTML=xmlDoc.getElementsByTagName("line08")[0].childNodes[0].nodeValue;

				document.getElementById("line09").innerHTML=xmlDoc.getElementsByTagName("line09")[0].childNodes[0].nodeValue;

				document.getElementById("line10").innerHTML=xmlDoc.getElementsByTagName("line10")[0].childNodes[0].nodeValue;

				document.getElementById("line11").innerHTML=xmlDoc.getElementsByTagName("line11")[0].childNodes[0].nodeValue;

				document.getElementById("line12").innerHTML=xmlDoc.getElementsByTagName("line12")[0].childNodes[0].nodeValue;

				document.getElementById("line13").innerHTML=xmlDoc.getElementsByTagName("line13")[0].childNodes[0].nodeValue;

				document.getElementById("line14").innerHTML=xmlDoc.getElementsByTagName("line14")[0].childNodes[0].nodeValue;

				document.getElementById("line15").innerHTML=xmlDoc.getElementsByTagName("line15")[0].childNodes[0].nodeValue;

				document.getElementById("line16").innerHTML=xmlDoc.getElementsByTagName("line16")[0].childNodes[0].nodeValue;

				document.getElementById("line17").innerHTML=xmlDoc.getElementsByTagName("line17")[0].childNodes[0].nodeValue;

				document.getElementById("line18").innerHTML=xmlDoc.getElementsByTagName("line18")[0].childNodes[0].nodeValue;

				document.getElementById("line19").innerHTML=xmlDoc.getElementsByTagName("line19")[0].childNodes[0].nodeValue;

				document.getElementById("line20").innerHTML=xmlDoc.getElementsByTagName("line20")[0].childNodes[0].nodeValue;

				document.getElementById("line21").innerHTML=xmlDoc.getElementsByTagName("line21")[0].childNodes[0].nodeValue;

				document.getElementById("line22").innerHTML=xmlDoc.getElementsByTagName("line22")[0].childNodes[0].nodeValue;

				document.getElementById("line23").innerHTML=xmlDoc.getElementsByTagName("line23")[0].childNodes[0].nodeValue;

				document.getElementById("line24").innerHTML=xmlDoc.getElementsByTagName("line24")[0].childNodes[0].nodeValue;

				document.getElementById("line25").innerHTML=xmlDoc.getElementsByTagName("line25")[0].childNodes[0].nodeValue;

				document.getElementById("line26").innerHTML=xmlDoc.getElementsByTagName("line26")[0].childNodes[0].nodeValue;

				document.getElementById("line27").innerHTML=xmlDoc.getElementsByTagName("line27")[0].childNodes[0].nodeValue;

				document.getElementById("line28").innerHTML=xmlDoc.getElementsByTagName("line28")[0].childNodes[0].nodeValue;

				document.getElementById("line29").innerHTML=xmlDoc.getElementsByTagName("line29")[0].childNodes[0].nodeValue;

				document.getElementById("line30").innerHTML=xmlDoc.getElementsByTagName("line20")[0].childNodes[0].nodeValue;

				document.getElementById("line31").innerHTML=xmlDoc.getElementsByTagName("line31")[0].childNodes[0].nodeValue;

				document.getElementById("line32").innerHTML=xmlDoc.getElementsByTagName("line32")[0].childNodes[0].nodeValue;

				document.getElementById("line33").innerHTML=xmlDoc.getElementsByTagName("line33")[0].childNodes[0].nodeValue;

				

			</script> 

</div>

Open in new window

0
Comment
Question by:swedesamurai
  • 2
2 Comments
 
LVL 9

Expert Comment

by:Lakio
ID: 24752255
Fastest, safest way is jquery!
www.jquery.com

http://think2loud.com/reading-xml-with-jquery/

I'll make a code for you when I get to work in an hour
0
 
LVL 9

Accepted Solution

by:
Lakio earned 500 total points
ID: 24752638
this should work and it also makes the HTML so you don't need that span army.

I can make this clearer if you prefer it.
$.get('test.xml', function(XML){

	var HTML='';

	$('rss>channel>*',XML).each(function(i){ HTML+='<span>'+$(this).text()+'</span>'; });

	$('body').prepend(HTML);

});

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Trouble inserting a variable  in javascript 7 42
XSL FO - text wrapping and empty spaces 1 26
SharePoint 2013 List with Ratings 6 39
Randomize in Owl Carousel v1.3.2 6 21
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now