payload differences IE/FF

eggwise's picture

Hi, I noticed the Mashup server stubs produce different payloads for IE and FF. This forced me to do something like this:

function showPayload(payload) {
if (typeof(payload) == "object" && payload.nodeType != undefined) {

if (browser == "ie" || browser == "ie7"){
var cmpc = payload.getElementsByTagName("datas1:code");
var cmpn = payload.getElementsByTagName("datas1:name");
}
else{
var cmpc = payload.getElementsByTagName("code");
var cmpn = payload.getElementsByTagName("name");

Is makes my code less transparent. Is there an other approach?

 

Thx,

 

 -Jan-Bart

tyrell's picture

Actually this happens due to

Actually this happens due to the way IE handles namespaces. When the response contains XML elements with namespaces FF is capable of differentiating the local name of the tag. But IE isn't. So you have to do it this way. If you install Firebug on FF and look at the response payload, you'll see it has the same elements (ex: "datas1:code") Tyrell
eggwise's picture

but ff cannot process "datas1:code"

Hu, Thanks, yes I noticed the behaviour, but to make my code suitable for IE and FF I still need the browserdetect because FF will not see the "datas1:code" as tagname, Right? My question was actually if there is an other way to handle this because the browserdetation looks ugly. thx, JB 8-)
tyrell's picture

JB, Yes. FF3 won't let you

JB, Yes. FF3 won't let you use "datas1:code" as a tag name. I remember FF2 used to let you get away with it :) In FF3 they properly implemented getElementsByTagNameNS(namespaceURI, localName), but still IE doesn't have it. So at the end of the day you will have to do browser detection in your code :( cheers, Tyrell
jonathan.wso2.com's picture

Blasted browser vendors!

So, what is returned from the stub is the same DOM structure in both browsers (modulo bugs). The issue is that the DOM APIs in FF and IE are not fully compatible, the ongoing bugaboo of many Web developers. Even the code you wrote assumes no namespace prefix changes, which is fragile if the message goes through some sort of normalization. Some solutions: 1) Sometimes you can redesign your service so it won't use namespaces. getElementsByTagname seems much more compatible when you avoid namespaces. 2) Use getElementsByTagnameNS, which is supported (IIRC) in IE and in FF3, although you'll still have to have a fallback for FF2 and older. 3) Use a framework to encapsulate browser differences, as well as make document manipulations easier. I prefer a very slim framework focussed just on DOM and Ajax interactions and not tons of code for visual widgets. My favorite is prototype.js (http://www.prototypejs.org/). As a bonus, we use this in the mashup server UI so you can include it simply by adding <script language="javascript" src="js/prototype.js" type="text/javascript"></script>. This framework doesn't have a specific alternative to getElementsByTagname, but it does allow you to search by CSS selectors: var cmpc = payload.$$("datas1::code"); var cmpn = payload.$$("datas1::name"); Maybe there's an even smaller framework that would suffice for adding namespace support into older Firefox versions. Or maybe we should start crafting our own XML DOM compatibility framework (Lord knows the stubs and WSRequest have enough browser detection cruft in them to make that appealing...) Let us know how you make out.
eggwise's picture

prototype,js

Hello Jonathan, Thank you for your explanation. I think I will explore the prototype.js as you suggest. Speak u later :-) Cheers, JB
jr97's picture

I ran into the same problem

I ran into the same problem developing in Adobe Flex. Workaround is to strip the namespace info with a reg expression in the result handler.
library project main code
Learn Cloud
Learn
Cloud

The WSO2 Application Server is a reliable application server that can host your enterprise web applications. The WSO2 Application Server as a Service is offered in StratosLive, the WSO2 Platform as a Service. This article explains how a simple web application can be developed and deployed from Carbon Studio to the WSO2 Application Server...

Latest Webinar
Different groups within an organization need to monitor different Key Performance Indicators (KPIs) - An operations team will be interested in the response times of business services and loads of each service,..
Thursday, February 9th 2012, 09.00 AM (PST)

Thursday, February 9th 2012, 10.00 AM (GMT)