Google V3 Maps API: XML Parsing

I am trying to update my Google Maps API web application, which I had excellent according to the second version. The third version, it seems, not only broke everything, but also put the burden of writing your own versions of many missing API functions that are no longer there.

Soooo, what was a relatively simple adaptation of their example “store locator” in version 2, turned into a giant headache.

In particular, my problem is to parse an XML document that returns the PHP / mySQL code after the user has entered some data on the web page and sent it to the server. I know that the test data that I entered works because 1. it worked flawlessly under V2 and 2. If I hard-link it to a PHP page and then load this page, I get the expected XML document loaded in my browser (Firefox 3.6.13 runs on Snow Leopard).

Update: after a very thorough trace with Firebug, I found that the "downloadUrl" function from here returns the data correctly.

However, it seems that the function "GXml.parse (data)" (from here ) does not process the returned XML. I am inserting this code below:

    function GXml(){}
GXml.value=value;
GXml.parse=parse;

function value(node){
     if(!node){
            return"";
     }
     var retStr="";
     if(node.nodeType==3||node.nodeType==4||node.nodeType==2){
            retStr+=node.nodeValue;
     }else if(node.nodeType==1||node.nodeType==9||node.nodeType==11){
            for(var i=0;i<node.childNodes.length;++i){
                 retStr+=arguments.callee(node.childNodes[i]);
            }
     }
     return retStr;
}


function parse(textDoc){
     try{
            if(typeof ActiveXObject!="undefined"&&typeof GetObject!="undefined"){
                 var b=new ActiveXObject("Microsoft.XMLDOM");
                 b.loadXML(textDoc);
                 return b;
            }else if(typeof DOMParser!="undefined"){
                 return(new DOMParser()).parseFromString(textDoc,"text/xml");
            }else{
                 return Wb(textDoc);
            }
     }
     catch(c){
            P.incompatible("xmlparse");
     }
     try{
            return Wb(textDoc);
     }
     catch(c){
            P.incompatible("xmlparse");
            return document.createElement("div");
     }
}

function P(){}
P.write=function(a,b){}
;P.writeRaw=function(a){}
;P.writeXML=function(a){}
;P.writeURL=function(a){}
;P.dump=function(a){}
;P.incompatible=function(){}
;P.clear=function(){}
;

function Wb(a){
     return null;
}
+3
2

XML-. JSON .. :

XML- JavaScript jQuery?

Duncan.

+1

Source: https://habr.com/ru/post/1791324/


All Articles