[OpenLayers-Dev] IE
Lorenzo Becchi
lorenzo at ominiverdi.com
Tue Jun 5 13:03:18 EDT 2007
Thanks you Tim,
I had a look at your code.
Tell me if I'm wrong but OpenLayers.parseXMLString is exactly the same
of OpenLayers.Format.XML.read.
I've pasted the code below.
my problem is actually that for some responses IE give back a complete
XML document and some others don't.
for ex:
Openlayers server works fine [1].
NASA blue marble don't [2].
try it here, please:
http://www.ominiverdi.org/openlayers/sandbox/openlayers/examples/wms_manager.html
Using IE, with Openlayers WMS server (the first of the list) you will
receive the list of layers available while with NASA (the second) you
will receive a "no layers available on this server".
Using Firefox, naturally, you receive both lists.
what I'm doing is:
//get the response text
var text = ajaxRequest.responseText;
//strip comments (helps with some servers: don't ask me why but works)
text = text.replace(/<!--.*?-->/g, '');
//get the XML Obj
var xml = OpenLayers.parseXMLString(text);
//check if this is an object
if(typeof xml=='object'){
...
var something = xml.getElementsByTagName('someTag');
}
nothing more
:-)
--------------------------------------------------------------------
read: function(text) {
var index = text.indexOf('<');
if(index > 0) {
text = text.substring(index);
}
var node = OpenLayers.Util.Try(
function() {
var xmldom = new ActiveXObject('Microsoft.XMLDOM');
xmldom.loadXML(text);
return xmldom;
},
function() {
return new DOMParser().parseFromString(text, 'text/xml');
},
function() {
var req = new XMLHttpRequest();
req.open("GET", "data:" + "text/xml" +
";charset=utf-8," + encodeURIComponent(text),
false);
if (req.overrideMimeType) {
req.overrideMimeType("text/xml");
}
req.send(null);
return req.responseXML;
}
);
return node;
},
--------------------------------------------------------------------
OpenLayers.parseXMLString = function(text) {
//MS sucks, if the server is bad it dies
var index = text.indexOf('<');
if (index > 0) {
text = text.substring(index);
}
var ajaxResponse = OpenLayers.Util.Try(
function() {
var xmldom = new ActiveXObject('Microsoft.XMLDOM');
xmldom.loadXML(text);
return xmldom;
},
function() {
return new DOMParser().parseFromString(text, 'text/xml');
},
function() {
var req = new XMLHttpRequest();
req.open("GET", "data:" + "text/xml" +
";charset=utf-8," + encodeURIComponent(text), false);
if (req.overrideMimeType) {
req.overrideMimeType("text/xml");
}
req.send(null);
return req.responseXML;
}
);
return ajaxResponse;
};
--------------------------------------------------------------------
ciao
Lorenzo
[1]['OpenLayers
WMS','http://labs.metacarta.com/cgi-bin/mapserv?map=/www/labs/map/vmap0.map'],//content
type: application/vnd.ogc.wms_xml
[2]['World - NASA Blue Marble Next
Generation','http://wms.jpl.nasa.gov/wms.cgi?'],
Tim Schaub wrote:
> Hey-
>
> Lance Dyas wrote:
>
>> Lorenzo Becchi wrote:
>>
>>> Hope somebody can help me solving IE XML parsing problem (WMSManager.js
>>> line 862) and Safari select issue (WMSManager.js line 674).
>>> Otherwise I'll go on "crying alone"
>>> :-)
>>>
>>>
>> The true horror of it is. IE has very poor xml parsing...in specific
>> NameSpaces and
>> Character Encodings are munged...and while there is "XML for <Script>" a
>> javascript
>> library which can for the most part by pass it.. well it adds a minimum
>> of 80kb to your
>> solution and over the web... that is quite a cost
>>
>
> I'm going to suggest OpenLayers.Format.XML for cross-browser xml-dom
> serializing/deserializing.
>
> I've only taken a quick hack at this, but you can see the results in
> this demo (serialize/deserialize GML):
> http://dev.openlayers.org/sandbox/tschaub/xml/examples/vector-formats.html
>
> In my mind, any format based on XML should subclass
> OpenLayers.Format.XML - these formats will inherit methods like
> createElementNS, getElementsByTagNameNS, etc.
>
> (I hope to deprecate the OpenLayers.Ajax and OpenLayers.Util that do
> this sort of thing for 3.0.)
>
> Tim
>
> - the code in this sandbox should not be considered stable or complete
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>
More information about the Dev
mailing list