SelectSingleNode doesn't work in Firefox and Netscape

The javascript code below works fine in IE, but failed in Firefox and Netscape:

productnode = dom.selectSingleNode("/downloadxml/productlist")

The error message is:
Error: dom.selectSingleNode is not a function

Any idea will be appreciated!
taoyuxinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChenChenCommented:

I tested it with my NS(7.0), it was fine.
Which version of Netscape do you have?

If <downloadxml> is the root node, I think you should use "downloadxml/productlist" without the leading slash in your xpath.
0
taoyuxinAuthor Commented:
Hi ChenChen,

Thank you for your responding.

My NS is 7.2. It still doesn't work. I paste my xml and code below:

Below is my xml:
<?xml version="1.0"?>
<downloadxml>
      <productlist>
            <product pid="13" pname="product1">
                  <software swid="3"></software>
                  <software swid="6"></software>
                  <software swid="16"></software>
                  <software swid="17"></software>
            </product>
            <product pid="7" pname="product2">
                  <software swid="3"></software>
                  <software swid="4"></software>
                  <software swid="5"></software>
                  <software swid="6"></software>
                  <software swid="22"></software>
            </product>
            <product pid="9" pname="product3">
                  <software swid="3"></software>
                  <software swid="17"></software>
                  <software swid="22"></software>
            </product>
      </productlist>
</downloadxml>

=================================================
And this is my javascript:

function loadxml() {
      var dom = null;

      var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument !='undefined');
      var ie = (typeof window.ActiveXObject != 'undefined');

      if (moz) {
            dom = document.implementation.createDocument("", "doc", null);
            dom.onload = "";

      } else if (ie) {
            dom = new ActiveXObject("Microsoft.XMLDOM");
            dom.async = "false";

            while(dom.readyState != 4) {}
      }
      dom.load("test.xml");
      return  dom;
}


function GetProductList() {
      var dom = null;
      dom = loadxml();
      if (dom) {
            var node = dom.selectSingleNode("downloadxml/productlist/product[0]");
            alert(node.nodeName)
      }
      
}

GetProductList();

=========================================
0
ChenChenCommented:
Hi taoyuxin,

I tested it on my netscape, it seemed fine, not getting any errors.

One thing I'd like to  point out, you are using  "Microsoft.XMLDOM" that is microsofte xml parsor. It normally comes with IE. So, do you have IE installed on you machine? and which version is it?

Microsofe xml parsor is fine, but it's highly recommended to use "MSXML2.Domdocument" which comes with IE5.5 or higher, rather than "Microsoft.XMLDOM", which is really bad.

If you don't want to install IE, than you'll need install the MS xml parsor to get your javascripts working. You can download the parsor from microsoft web sit.

Cheers
ChenChen
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ChenChenCommented:

Hi taoyuxin,

I installed firefox and had a test on you javascript. I am getting the same error. So, it looks like the activex which is microsoft isn't supported by this browser.

I don't know the background of your project; but I think you should try to avoid using those "non-standard" technologies (i.e. ActiveX for your case) on the client side, because it can't be guaranteed to work on all browsers. Experts would thumb down it and many users would be turned away if your website is IE only or they have to perform some sort of installation before they can get into it.

0
taoyuxinAuthor Commented:
Thanks for your advisement ChenChen. I am new to xml, so what is your suggestion to get the data from xml through javascript, other than using ActiveX? Thanks!
0
ChenChenCommented:
OK, where is the xml stored?  on server or on client side? if on server side, what type of server is it?
0
taoyuxinAuthor Commented:
The xml is stored on server. The server is running MS Windows 2000, and IIS.
0
ChenChenCommented:

OK, I would suggest you to use microsoft xml parsor ("MSXML2.DOMDocument") in ASP or ASP.Net - both of them run on server. If you are familiar with javascripts syntax, you can use JScript. or maybe c# if you want to use .net.  you can find more info through these links:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/dom_hdi_overview.asp

http://www.devguru.com/Features/tutorials/usingxml/usingxml.htm

I guess you also want to tranform you xml data into  html so that you can display it on client's browser, right?
XSLT is the best choice!

http://www.w3schools.com/xsl/default.asp

hope it helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
taoyuxinAuthor Commented:
Hi ChenChen, thank you for your comment. I changed to another project last month, now I am back, sorry for the delay in response.
Now I changed my code on server side, so that I don't need to worry about the client browser. And thank you for your reference links, I've learned alot from it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.