Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2008, 03:51 PM
Authorized User
 
Join Date: Oct 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML in JavaScript for Mozilla

Okay, I'm having trouble making my application fly in Mozilla, using Firefox 2.0.0.11 as a test platform. Using web searches for "JavaScript XML" and the like I've found many good examples for loading and parsing XML in JavaScript... I'm already familiar with loading and parsing XML in ActionScript and classic ASP, so the basics haven't been that difficult.

I've got the whole thing working just fine if I use a static XML page. If I call an ASP page to build a dynamic XML, however, only the MSIE portion of the code functions. The code is not changing, so it's something to do with the difference between static and dynamically constructed XML.

With the understanding that it's dirty because I'm still trying to hack it all together, here's the XML code for your review:

        var xmlPath = "GUI_GET_AssetLocations.asp"

        //(loadXML function called on page load)

        function loadXML()
        {
            // Check for Mozilla browser type
            if (document.implementation && document.implementation.createDocument)
            {
                // Build XMLDOM object and establish "onload" event for Mozilla
                xmlDoc = document.implementation.createDocument("", "", null);
                xmlDoc.ignorewhitespace = true;
                xmlDoc.onload = display;
            }
            // Check for Internet Explorer browser type
            else
            {
                // Build XMLDOM object and establish "onload" event for MSIE
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.onreadystatechange = function ()
                {
                    if (xmlDoc.readyState == 4) display()
                };
            }
            // Load XML based on passed path
            xmlDoc.load(xmlPath);
        }

        function display()
        {
            //
            var xmlTags = xmlDoc.getElementsByTagName('location');
            //
            for (var i=0;i<xmlTags.length;i++)
            {
                //
                var nodeLoop = xmlTags[i].childNodes.length;
                //
                for (var ii=0; ii<nodeLoop; ii++)
                {
                    //
                    var nodeContents = xmlTags[i].childNodes[ii];
                    //
                    var nodeLabel = nodeContents.nodeName;
                    //
                    if (nodeContents.childNodes.length > 0)
                    {
                        var nodeData = nodeContents.firstChild.nodeValue;
                    } else {
                        var nodeData = ""
                    }
                    //
                    if (nodeLabel == "id")
                    {
                        var dataId = nodeData
                    }
                    //
                    if (nodeLabel == "name")
                    {
                        var dataName = nodeData
                    }
                    //
                    if (nodeLabel == "lat")
                    {
                        var dataLat = nodeData
                    }
                    //
                    if (nodeLabel == "long")
                    {
                        var dataLong = nodeData
                    }
                    //
                    if (nodeLabel == "almstattxt")
                    {
                        var dataAlarm = nodeData
                    }
                    //
                    if (nodeLabel == "icon")
                    {
                        var dataIcon = customIconPre + nodeData + customIconSuf
                    }
                }
                //
                AddPin(dataId, dataName, dataLat, dataLong, dataAlarm, dataIcon);
                //
                //alert(dataId + ";" + dataName + ";" + dataLat + ";" + dataLong + ";" + dataAlarm);
            }
        }
 
Old February 6th, 2008, 03:58 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Do you mean the code works if the line
Code:
var xmlPath = "GUI_GET_AssetLocations.asp"
is replaced by a pointer to a static XML file?
If so then I suspect that you are not correctly assigning the content type as text/xml although there could be a number of reasons. What happens if you browse to GUI_GET_AssetLocations.asp directly?

--

Joe (Microsoft MVP - XML)
 
Old February 6th, 2008, 11:47 AM
Authorized User
 
Join Date: Oct 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, that is exactly what I mean... Except that it works fine either way in MSIE, just not in Mozilla.

I've actually been using classic ASP for a number of years (close to 10) to deliver data in XML format to Flash ActionScript, Visual Basic, and many other platforms... This ASP is built the same way as I have always built them. In fact, the *exact* ASP page this process hits is also being hit by a Flash application that has no problem reading the resulting XML. (Also noting again that the ASP, and indeed the whole process, *does work* when the JavaScript code is being viewed in MSIE, just not Firefox.)

But, as a point of interest, here is the result of hitting the ASP directly: (If you save this as a static XML file and test it with the above code, it will work... The exact same test works here also.)

<?xml version="1.0" encoding="UTF-8" ?>
<content>
 <location>
  <id>3</id>
  <name>Denver CO</name>
  <desc>Denver CO</desc>
  <desctype>Text</desctype>
  <icon>iconLoc2</icon>
  <lat>39.741</lat>
  <latid>5</latid>
  <long>-104.99</long>
  <longid>6</longid>
  <dlat />
  <dlatid />
  <dlong />
  <dlongid />
  <almstattxt>No Alarm</almstattxt>
  <almstatval>-1</almstatval>
  <fencerad />
  <fenceradid />
  <doorstattxt />
  <doorstatval />
  <doorstatid />
  <dist />
  <icox>0</icox>
  <icoy>0</icoy>
  </location>
 <location>
  <id>325</id>
  <name>(edited)</name>
  <desc>(edited)</desc>
  <desctype>Text</desctype>
  <icon>iconTug2</icon>
  <lat>27.470745</lat>
  <latid>7</latid>
  <long>-91.142514</long>
  <longid>8</longid>
  <dlat />
  <dlatid />
  <dlong />
  <dlongid />
  <almstattxt>No Alarm</almstattxt>
  <almstatval>-1</almstatval>
  <fencerad />
  <fenceradid />
  <doorstattxt />
  <doorstatval />
  <doorstatid />
  <dist />
  <icox>-27</icox>
  <icoy>-59</icoy>
  </location>
 <location>
  <id>326</id>
  <name>(edited)</name>
  <desc>(edited)</desc>
  <desctype>Text</desctype>
  <icon>iconTug2</icon>
  <lat>29.669523</lat>
  <latid>9</latid>
  <long>-91.085758</long>
  <longid>10</longid>
  <dlat />
  <dlatid />
  <dlong />
  <dlongid />
  <almstattxt>No Alarm</almstattxt>
  <almstatval>-1</almstatval>
  <fencerad />
  <fenceradid />
  <doorstattxt />
  <doorstatval />
  <doorstatid />
  <dist />
  <icox>-27</icox>
  <icoy>-59</icoy>
 </location>
</content>





Similar Threads
Thread Thread Starter Forum Replies Last Post
firefox/mozilla crash: javascript in XSLT stekker XSLT 4 May 3rd, 2006 04:15 PM
Transform XML with XSLT in JavaScript Mozilla Spankmaster79 Javascript 3 January 18th, 2006 07:31 AM
XML and netscape / mozilla madhukp XML 1 May 21st, 2004 04:01 PM
XML and netscape / Mozilla madhukp Classic ASP XML 0 May 3rd, 2004 04:24 AM
XML, XML Schema, JavaScript, ASP cyberjames2003 XML 0 June 4th, 2003 04:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.