[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 682
  • Last Modified:

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!
0
taoyuxin
Asked:
taoyuxin
  • 5
  • 4
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now