473,408 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Why does this javascript xml work in Firefox and not Safari?

Here is the html code

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6.   <title>test xml import</title>
  7. <script type="text/javascript">
  8.     var xmlDoc;
  9.     // code for IE
  10.     if (window.ActiveXObject)
  11.     {
  12.         xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  13.     }
  14.     // code for Mozilla, Firefox, Opera, etc.
  15.     else if (document.implementation && document.implementation.createDocument)
  16.     {
  17.         xmlDoc=document.implementation.createDocument("ns","root",null);
  18.     }
  19.     else
  20.     {
  21.         alert('cannot handle this');
  22.     }
  23.     xmlDoc.async=false;
  24.     xmlDoc.load("../xml/badgirls_shows2.xml");
  25. </script>
  26.  
  27. </head>
  28. <body>
  29.  
  30. <script language="javascript">
  31. var whovar=xmlDoc.getElementsByTagName('who');
  32. var picturevar=xmlDoc.getElementsByTagName('picture');
  33. var descriptionvar=xmlDoc.getElementsByTagName('description');
  34.  
  35. for (i=0;i<whovar.length;i++)
  36.   {
  37.   if (whovar[i].nodeType==1)
  38.     {  
  39.       document.writeln("<br />");
  40.       document.writeln(whovar[i].childNodes[0].nodeValue);
  41.       document.writeln("<br />");
  42.       document.writeln("<img src='../" + picturevar[i].childNodes[0].nodeValue + "'>");
  43.       document.writeln("<br />");
  44.       document.writeln(descriptionvar[i].childNodes[0].nodeValue);
  45.       document.writeln("<br />");
  46.      }
  47.   }
  48.   </script>
  49. </body>
  50. </html>
  51.  
Here is the xml file
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <cast>
  5.     <member>
  6.         <who>Leslie Ramsue, 24</who>
  7.         <picture>global_images/bg/leslie.jpg</picture>
  8.         <description>Leslie Ramsue is a 24 year-old exotic dancer from Atlanta, Georgia, who realizes the path she's on and doesn't want to dance for much longer. She's a self-proclaimed dare-devil!  For fun she rides her motorcycle and works out in the gym.  Leslie thinks that a bunch of women under one roof for four months is a hilarious idea.  Although she wishes everybody could be cordial to each other, she knows it's just not going to happen! </description>
  9.     </member>
  10.     <member>    
  11.         <who>Aimee Landi, 24</who>
  12.         <picture>global_images/bg/aimee.jpg</picture>
  13.         <description>Aimee Landi is an abrasive 24 year-old Italian girl from South Philadelphia.  She gets into physical fights from time to time, which she credits to her father, who used to encourage her to stand up for herself. She believes she doesn't need to take attitude from anyone and reacts harshly to any criticism. She's a loudmouth who doesn't get along with girls and can't hold a job because of her tell-it-like-it-is persona.</description>
  14.     </member>
  15.     <member>
  16.         <who>Zara Sprankle, 22</who>
  17.         <picture>global_images/bg/zara.jpg</picture>
  18.         <description>Zara Sprankle, 22, is a self-proclaimed "the most crazy, sexy, super person from the smallest town ever" up state New York. Outgoing and with a bent for manipulating she wants to meet other strong "bitches" that she can relate to.  She loves the camera and doesn't mind showing of her private story, the good and the bad parts. </description>
  19.     </member>
  20.     <member>
  21.         <who>Ripsi Terzian, 23</who>
  22.         <picture>global_images/bg/ripsi.jpg</picture>
  23.         <description>Ripsi Terzian, 23, is an admittedly spoiled Armenian girl who has never lived apart from her parents.  She confesses that until she was eight years old, she thought she was an actual princes. With attitude for miles, Ripsi is confrontational, materialistic and opinionated. She is judgmental of promiscuous girls and cheap people. Although she hasn't had much luck with befriending women, she would love to have a girlfriend like herself: fun, outgoing and with a neck for drama.</description>
  24.     </member>
  25.     <member>
  26.         <who>Jodie Howell, 29</who>
  27.         <picture>global_images/bg/jodie.jpg</picture>
  28.         <description>Jodie Howell, 29 hailing from Baltimore is a hot Playboy Bunny blonde with a brain.  Conservative office worker by day, Jodie turns into a sexy social butterfly at night, often engaging in fights with girls in bars.  A rebel from a religious background, Jodie loves to have fun and confesses to her vindictive and outrageous behavior. She owns her bad-girl persona with no apologies. </description>
  29.     </member>    
  30.     <member>
  31.         <who>Kerry Harvick, 31</who>
  32.         <picture>global_images/bg/kerry.jpg</picture>
  33.         <description>Kerry Harvick, 31, is a fairly well celebrated singer known as "the sex kitten of country music."  She has recently been dropped by her record label and management for irresponsible behavior. Despite being surrounded by motivated people from her profession, she seems to stray frequently as her professional itinerary pales in importance next to her social commitments.  She has all the tools to be successful but can't quite keep to the straight and narrowÉ </description>
  34.     </member>
  35.     <member>
  36.         <who>Ty Colliers, 25</who>
  37.         <picture>global_images/bg/ty.jpg</picture>
  38.         <description>A 25 year old ex-stripper and an ex-porn star, Ty Colliers defines "edgy bad girl."  She declares herself a hustler for a living and has even done some jail time as a juvenile for running away from a foster home. She says she has a temper, but she'd like to someday be a positive influence to girls that have struggled with circumstances similar to her own. </description>
  39.     </member>
  40.     </cast>
  41.  
May 14 '07 #1
3 9666
Hey Everyone,

I found the answer in a tutorial online -- http://www.webdeveloper.com/forum/showthread.php?threadid=147548

I guess I have to use XMLHttpRequest for safari

Expand|Select|Wrap|Line Numbers
  1.  
  2. else if(window.XMLHttpRequest)
  3.         {
  4.             var errorHappendHere = "Error handling XMLHttpRequest request";
  5.             var d = new XMLHttpRequest();
  6.             d.open("GET", rssFeed, false);
  7.             d.send(null);
  8.             xmlDoc=d.responseXML;
  9.  
  10.  
Now I have to figure out why it's not working Win IE :-)
May 15 '07 #2
dorinbogdan
839 Expert 512MB
Welcome to TheScripts TSDN....

For IE, you may use new ActiveXObject("Microsoft.XMLHTTP").

For more details, take an overview on these articles.
May 15 '07 #3
Welcome to TheScripts TSDN....

For IE, you may use new ActiveXObject("Microsoft.XMLHTTP").

For more details, take an overview on these articles.
Thanks for the Welcome :-) I found the answer shortly after posting the question. I'm beginning to think that this is the magic forum, where you find your answers after posting, then feeling like a fool :-)

Here's the latest snag in the code:

I was able to retrieve data from the most of the xml files except the ones that contain attributes but I have yet to find a tutorial that explains the retrieval of the attributes of a node.

Expand|Select|Wrap|Line Numbers
  1. The xml:
  2.  
  3.         <title>Episode 101 - DECEMBER 5TH, 2006</title>
  4.         <music songname="'Main Title Theme: Love Me Or Hate Me' by LADY SOVEREIGN" songurl="http://www.ladysovereign.com"></music>
  5.         <music songname="'Heads Will Roll' by MARION RAVEN" songurl="http://www.marion-raven.com/"></music>
  6.         <music songname="'All Right' by THE ETTES" songurl="http://www.myspace.com/theettes"> </music>
  7.         <music songname="'OK, OK' by SLUNT" songurl="http://www.myspace.com/slunt"> </music>
  8.         <music songname="'Here I Come' by FERGIE" songurl="http://www.fergie.blackeyedpeas.com/"> </music>
  9.         <music songname="'Shoot From The Hip' by A CHANGE OF PACE" songurl="http://www.achangeofpacemusic.com/"> </music>
  10.         <music songname="'Reputation' by THE ETTES" songurl="http://www.myspace.com/theettes"> </music>
  11.         <music songname="'Love Is All That Matters' by SARA HAZE" songurl="http://www.myspace.com/sarahaze"> </music>
  12.         <music songname="'TV Land' by SUPERCHICK" songurl="http://www.superchickonline.com/"> </music>
  13.  
  14. The javascript:
  15.  
  16. var titlevar=xmlDoc.getElementsByTagName('title');
  17. var musicvar=xmlDoc.getElementsByTagName('music');
  18. var songvar=musicvar.getElementsByAttribute('songname');
  19. var urlvar=musicvar.getElementsByAttribute('songurl');
  20.  
  21. for (i=0;i<titlevar.length;i++)
  22.   {
  23.   if (titlevar[i].nodeType==1)
  24.     { 
  25. document.writeln(titlevar[i].childNodes[0].nodeValue);
  26. document.writeln("<br>");
  27. document.writeln(musicvar[i].childNodes[0].nodeValue);
  28. document.writeln("<br>");
  29.     }
  30.   }
  31.  
How do I get the attributes of the childnodes?

I'll post the response as a new post.
May 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Prometheus Research | last post by:
http://newyork.craigslist.org/eng/34043771.html We need a JavaScript component which will auto-submit a form after a set period has elapsed. The component must display a counter that dynamically...
5
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have...
6
by: Giuseppe Chielli | last post by:
Hi! I'm new to this newsgroup. I have a problem: I need to get the window size via Javascript; I usually use window.innerWidth or document.body.clientWidth with IE and Firefox and it properly...
9
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE...
3
by: Joe Cox | last post by:
I am having a problem with style properties for dynamic images in Mac OS X Safari. By dymanic images, I mean images allocated with the javascript 'new Image()' call. With static images (created...
7
by: Xah Lee | last post by:
Look at this page http://xahlee.org/emacs/wrap-url.html Look at it in Firebox, look at it in Safari, in Opera, and look at it in Microsoft Internet Explorer. The only fucked up case, is...
48
by: Nathan Sokalski | last post by:
Ever since I found out that they didn't give us a way to install both IE6 and IE7 on the same machine, I have been more frustrated and annoyed with Microsoft than I ever have been with any company...
2
by: npm | last post by:
Hi, I've got this javascript to load elements from my xml file. It works in both Firefox and IE6, but I tried it on my friend's Mac using Safari and it came up blank. Here's the xml: ...
5
by: loveshack | last post by:
Can anyone help me please (i am quite a novice, but having fun learning). Im not sure if this is an ASP problem, a javascript problem or a browser problem. Firstly, everything i have written...
2
by: joelkeepup | last post by:
Hi, I made a change this morning and now im getting an error that says either "a is undefined or null" or "e is undefined or null" the microsoft ajax line is below, I have no idea how to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.