Link to home
Start Free TrialLog in
Avatar of RozanaZ
RozanaZ

asked on

loadXML in FF

Hi Experts,

I have a problem with the following code. The problem is that code works in IE and doesn't work in FF.
Please advice.

Thanks in advance

<HTML>
<HEAD>
<TITLE></TITLE>
<script>
function getXMLDocument()
      {
            var xDoc=null;
            if (document.implementation
                              && document.implementation.createDocument)
            {
                  xDoc=document.implementation.createDocument("","",null);
            }
            else if (typeof ActiveXObject != "undefined")
            {
                  var msXmlAx=null;
                  try
                  {
                              msXmlAx=new ActiveXObject("Msxml2.DOMDocument");
                  }
                  catch (e)
                  {
                        msXmlAx=new ActiveXObject("Msxml.DOMDocument");
                  }
                  xDoc=msXmlAx;
            }
            if (xDoc==null || typeof xDoc.load=="undefined")
            {
                  xDoc=null;
            }
            return xDoc;
      }

var txt = "<ruleValues><rule_value><value>v 1</value><name>value 1</name></rule_value><rule_value><value>v 2</value><name>value 2</name></rule_value></ruleValues>";
function test()

{
      xmldoc = getXMLDocument();
      //xmldoc.load("xml.xml");      
      xmldoc.loadXML(txt);
      ruleValues = xmldoc.getElementsByTagName("ruleValues");
      ruleValueNodes = ruleValues(0).childNodes;
      for (i = 0;  i < ruleValueNodes.length; i++)
      {
            valueNode = ruleValueNodes(i);
            id =  valueNode.childNodes(0).text;
            value =  valueNode.childNodes(1).text;
            alert("ID: " + id + " value: " + value);
      }      
}
</script>
</HEAD>
<BODY>
<input type="button" value="Test" onClick="test()">
</BODY>
</HTML>
ASKER CERTIFIED SOLUTION
Avatar of Suat M. Ozgur
Suat M. Ozgur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can see following page for retrieving XML Data for Firefox and differences between IE and Firefox.
http://www.webreference.com/programming/prof_ajax/3.html

Suat
Avatar of RozanaZ
RozanaZ

ASKER

Just perfect!
Thanks a lot!
You're welcome!

Thanks for the A grade!
Suat