Reputation: 2001
I want to move Google maps from v2 to v3 in one of the applications I am developing. I saw this link Tips for Upgrading Gmaps v2 to v3 more quickly. I could however not find an alternative for GXml.parse method in v2 API.
I am using downloadUrl function provided by this script http://gmaps-samples-v3.googlecode.com/svn/trunk/xmlparsing/util.js.
function renderMap(mapControlFile) {
if (!mapControlFile || !xmlPath) {
downloadUrl(mapConfigFile, function(data,responseCode) {
try {errorTest = errorTest;}
catch(e) {errorTest = null;}
if (responseCode!=200 || errorTest=='yes') {
document.getElementById('mapCanvas').innerHTML = mapDataError;
document.getElementById('mapCanvas').innerHTML += '<p>Response Code: '+responseCode+'</p>';
return;
}
// The below line uses GXml which is now deprecated in v3
xmlDocument = GXml.parse(data);
//process config element -- restricted to 1 config element in the xml file
configElement = xmlDocument.documentElement.getElementsByTagName("config");
//check for xml file parsing errors
if (configElement.length==0) {
document.getElementById('mapCanvas').innerHTML = mapDataError; //<div> tag in html document
return;
}
//try-catch handler for potential undeclared variable "auth" across all browsers (controls access during maintenance)
try {auth = auth;}
catch(e) {auth = null;}
//try-catch handler for potential undeclared variable "maintenanceTest" across all browsers (used for maintenance message testing)
try {maintenanceTest = maintenanceTest;}
catch(e) {maintenanceTest = null;}
//check if campus map system is offline for maintenance
if ((GXml.value(configElement[0].getElementsByTagName("offline")[0]) && auth==null) || maintenanceTest=='yes') {
document.getElementById('mapCanvas').innerHTML = GXml.value(configElement[0].getElementsByTagName("offlineMsg")[0]); //<div> tag in html document
return;
}
//initialize and load default map
xmlPath = GXml.value(configElement[0].getElementsByTagName("xmlPath")[0]);
overlayURL = GXml.value(configElement[0].getElementsByTagName("overlayURL")[0]); //set global variable
//create map and add controls (documentation at http://code.google.com/apis/maps/documentation/)
//map canvas is styled in ../css/campusmaps.css
//Google Maps API Version 2
map = new GMap2(document.getElementById("mapCanvas")); //<div> tag in html document
eval('map.setMapType('+GXml.value(configElement[0].getElementsByTagName("mapType")[0])+')');
map.addControl(new GSmallZoomControl3D());
zoomLevelMessage = GXml.value(configElement[0].getElementsByTagName("zoomLevelMessage")[0]); //set global variable
parseXml(xmlPath+GXml.value(configElement[0].getElementsByTagName("defaultMap")[0])); //function call to parse xml default map control file
}); //end downloadUrl()
} //end initialize and load default map
else {
parseXml(xmlPath+mapControlFile); //function call to parse xml map control files
} //end load all non-default maps
} //end renderMap()
Upvotes: 0
Views: 1271
Reputation: 161334
You have some options.
Option 2:
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");
}
}
Option 3:
function xmlParse(str) {
if (typeof ActiveXObject != 'undefined' && typeof GetObject != 'undefined') {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
}
if (typeof DOMParser != 'undefined') {
return (new DOMParser()).parseFromString(str, 'text/xml');
}
return createElement('div', null);
}
Upvotes: 1