-
Safari XSL/XML Problem
Hi
I am a new coder and have just developed a dynamic site using XSL/XML. I do not know javascript and I have used a variety of sources to incorporate into my HTML. The site works fine on everything except Safari and I use the following javascript to load my XML and XSL.
I am I missing code or am I using the wrong script? Any help will be appreciated.
<script type="text/javascript">
var xmlDoc;
{
// code for IE
if (window.ActiveXObject)
{
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async=false;
xml.load("artistlist.xml");
// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
xsl.load("artistlist.xsl");
// Transform
document.write(xml.transformNode(xsl))
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.async=false;
xmlDoc.load("artistlist.xml");
var xsltProc = new XSLTProcessor();
var xsl=document.implementation.createDocument("","",null);
xsl.async=false;
xsl.load("artistlist.xsl");
xsltProc.importStylesheet(xsl);
xmlDoc=xsltProc.transformToDocument(xmlDoc);
var serializer=new XMLSerializer();
document.write(serializer.serializeToString(xmlDoc));
}
else
{
alert('Your browser cannot handle this script');
}
}
</script>
-
-
I don't know much about the methods used in your code, but what happens in Safari? If you get the alert, it simply means that Safari doesn't support either of the two methods. If it is something else, Safari has an optional javascript console for reporting errors, I'd suggest using it.
-
-
Thanks for your suggestion. I used the Safari Javascript Console which gave the following error:
"Type error: Value undefined (Result of expression XMLDOC.Load is not object)"
..
xmlDoc.load("artistlist.xml");
..
and
..
xsl.load("artistlist.xsl");
..
are fine for Mozilla, Firefox, Opera, etc. Do you know the equivalent that should be used for Safari? Any help will be appreciated.
Tom
-
-
This xml stuff is really a bit out of my area, as I just haven't done all that much with it. I did take a look around at a few examples and none of them worked in Safari. Quirksmode.org, which is a very good resource on what works in which browsers wasn't as much help as I had hoped because they only went up to Safari 1.3. However there was no support there (for importation of xml to HTML) while IE 6 and Mozilla 1.6 did. I took this, along with some of the other stuff I was able to Google on the subject to mean that it is very possible that Safari, while supporting the:
document.implementation.createDocument
object, doesn't support the importation of xml data to an HTML page. the only thing I found that looked promising was:
http://xmljs.sourceforge.net/index.html
But I found that there was too much documentation to weed through to get a straight answer in a reasonable amount of time. You might want to check it out though, as it appears to be quite exhaustive on the subject.
-
-
Thanks for all your hard work. Greatly appreciated. I'll tackle the site you pointed me to and I'll let you know how I get on.
Tom P
-
-
I have found the solution
try this
<html>
<body>
<script type="text/javascript">
var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("cd_catalog.xml");
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET","cd_catalog.xml",false);
xmlhttp.send(null);
var xmlDoc = xmlhttp.responseXML.documentElement;
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td>");
document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>
</body>
</html>
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks