Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active X

Status
Not open for further replies.
Apr 20, 2005
27
GB
I've got a script which uses an Active X applet to run an XML parser. This works fine in IE but obviously does not in FF, due to it not supporting Active X.

I'd like my site to be as accessible as possible so I was wondering if there is a happy medium I could use? Something which works in both browsers.

Any suggestions much appreciated
 
No problems, another forum I used didn't allow its users to post code for some reason, that's all.

The JS file is:

function go()
{
if(document.implementation && document.implementation.createDocument)
{
// Mozilla

// Load XML
var xml = document.implementation.createDocument("", "", null);
xml.load("results.xml");

xml.onload = function()
{
// Load XSL
var xsl = document.implementation.createDocument("", "", null);
xsl.load("stylesheet.xsl");

xsl.onload = function()
{
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);

//Change parameter
xsltProcessor.setParameter(null, "fieldvalue", document.getElementsByName("fieldvalue")[0].value);

// Transform
result = xsltProcessor.transformToDocument(xml);
document.removeChild(document.firstChild);
document.appendChild(result.firstChild);
}
}
}
else if(window.ActiveXObject)
{
// IE

// Load XML
xml = new ActiveXObject("MSXML2.DOMDocument");
xml.async = false
xml.load("results.xml")

// Load XSL
xsl = new ActiveXObject("MSXML2.DOMDocument");
xsl.async = false
xsl.load("stylesheet.xsl")

//Change parameter
xsl.selectSingleNode("//xsl:param[@name='fieldvalue']").setAttribute("select", "'"+document.forms[0].fieldvalue.value+"'")

// Transform
document.write(xml.transformNode(xsl))
}
else
{
// Browser unknown
alert("Browser unknown");
}
}
}

This file is accessed as soon as a user submits a form located on my website. The destination page is 'results.xml' and the value of the form I'm taking comes from the field named 'fieldvalue'.

The form works fine in IE but not in Firefox - it always returns the error:

Error: document.getElementsByName("fieldvalue")[0] has no properties

Which suggests to me it can't understand what 'fieldvalue' is. I don't understand this message, so I'm thinking there has to be a more practical way of doing this, rather than testing the browser then assigning a compatible solution.
 
Is there any way you could do this on the server side instead of the client?

If you could do it that way it wouldnt matter what browser they used.
 
Right, thanks. Is there a particular forum on here that could give me some advice on server side applications? This problem kinda falls into various categories (XML/Browsers/ActiveX). Thanks
 
petejohnson,

Try modified this part.
[tt]
if(document.implementation && document.implementation.createDocument)
{
// Mozilla

// Load XML
var xml = document.implementation.createDocument("", "", null);
[red]xml.async=false;[/red]
[red]var xmldone=[/red]xml.load("results.xml");
[red]var sget;[/red]
[red]if (xmldone) {
sget=xml.getElementsByName("fieldvalue")[0].value;
}[/red]
xml.onload = function()
{
// Load XSL
var xsl = document.implementation.createDocument("", "", null);
xsl.load("stylesheet.xsl");

xsl.onload = function()
{
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);

//Change parameter
xsltProcessor.setParameter(null, "fieldvalue", [red]sget[/red]);

// Transform
result = xsltProcessor.transformToDocument(xml);
[red]xml[/red].removeChild([red]xml[/red].firstChild);
[red]xml[/red].appendChild(result.firstChild);
}
}
}
//followed by : else if(window.ActiveXObject) line
[/tt]
regards - tsuji
 
Hi tsuji

Thanks for trying that. Unfortunately it still doesn't work - Firefox still returns the error:

Error: document.getElementsByName("fieldvalue")[0] has no properties
Line: 31

It's strange that FF can't find 'fieldvalue' yet IE can.
 
petejohnson,
It cannot find only because the loading is not done.
- tsuji
 
Oh, I kinda get it now. What loading are you talking about? It seems the Firefox page loads the script then fails, returning back to the form page, seemingly doing nothing. There's no loading left for it to do.
 
petejohnson,
I meant
[tt] xmldone=xml.load("results.xml");[/tt]
may fail, in the sense of timing as well. If it is successful, ff would have no reason not to find the element. Do some more research on securing the good behavior or this line. In particular, you might have to implement onreadystatechange event handler. Get rid of other functionality for testing.
- tsuji
 
I'm not an expert JavaScript user - this feature is an addition to my site which is out of the scope of my current knowledge.

Would it be simpler to use a server-side implementation? I'm not being lazy, I just don't know JavaScript well enough. My main areas are XML/XLST.
 
After talking to a few other people, it seems a server side solution would be easier - at least I could ensure everyone would be able to view my site.

I'd like some advice... is there anyone here that could perhaps give me their opinion on this?
 
petejohnson,

I think all is the lost yet. When you load("xxx.xml"), the objDOM is not really supporting getElementById. To retrieve the one node you have useful info, you can do it by using the definitely supported .getElementsByTagName which gives you a collection, zero-indexed up to the .length-1. From each element so bound to, you use again the .getAttribute("id") (case may be sensitive here) to identify the target element. Once this is done, you retrieve the info.

Once .asyn is set to false, the loaded to be returned true if you have a valid xml file. It is very strict here. If anything wrong in the xml would fail all the following operations.

A re-think of the realization may be good. But, I think the existing script can be salvaged following this reasoning.

- tsuji
 
If you can manage to get it to work in either JavaScript or VBScript then you could do it once ond the server and then browsers could get only the formatted output. To me that would be easier than worrying about different scripts for diferent browsers and also some people that have disabled client script for security reasons.

Sometimes you really just cant get around doing this sort of work on the client but it just depends on the design of your web app.

I think it was Einstein that said to make things as simple as possible, but not simpler... What I'm trying to say is don't force it onto the server if that doesnt work in your app design but if it does work for your site then it would be the simpliest way.
 
Thanks for your help tsuji and Sheco.

As I mentioned earlier, my main area of 'expertese' is XSLT. The above JavaScript was kindly given to me by another user, as I don't enough JS or VB to create a script of my own.

Do you know of anyone on this site who may be able to help me with the implementation? I'd obviously fully reference their help. I really don't know enough about client side/server side solutions to get this working.

If required, I can provide the context into which this script is placed.

Many thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top