Connecting Tech Pros Worldwide Help | Site Map

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

Member
 
Join Date: May 2007
Posts: 63
#1: May 14 '07
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.  
Member
 
Join Date: May 2007
Posts: 63
#2: May 15 '07

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


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 :-)
dorinbogdan's Avatar
Expert
 
Join Date: Feb 2007
Posts: 822
#3: May 15 '07

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


Welcome to TheScripts TSDN....

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

For more details, take an overview on these articles.
Member
 
Join Date: May 2007
Posts: 63
#4: May 16 '07

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


Quote:

Originally Posted by dorinbogdan

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.
Reply