PDA

View Full Version : [OPEN] [4.0.2] XmlReader + XmlStore in Firefox



mrobinson
15 Jun 2011, 6:22 AM
I'm very new to sencha's products. Attended the fast track to sencha touch in Boston a couple of weeks ago, but what I really need to work on is ExtJS 4 right now.

What I'm trying to do now is to consume a vendor's XML REST webservices with an XmlStore & XmlReader and I can do it in Safari but not Firefox. In safari it works as expected, in Firefox the data doesn't seem to move from the proxy (it looks the same between ff & safari in the store.proxy.reader.xmlData property) into the data property of the store and I cannot figure out why.

The XML is namespaced, but it doesn't seem to matter if I strip out the name space from the XML. It seems like the xml reader is parsing the XML correctly, but its just not getting into the store's data element. There are no errors or warnings being thrown in FF 4 or 3.6

Here is the XML:


<?xml version="1.0"?>
<r25:login_challenge xmlns:r25="http://www.collegenet.com/r25" xmlns:xl="http://www.w3.org/1999/xlink" pubdate="2011-06-09T09:51:27-04:00">
<r25:login>
<r25:challenge>8534ec8cf33ef5cee3d256d995ca3d87</r25:challenge>
<r25:username/>
<r25:response/>
</r25:login>
</r25:login_challenge>
Here's my javascript:


loginLoaded = function(records)
{
console.log(records);
console.log(records.getAt(0).get("challenge"));
}

Ext.define('modelLogin',
{
extend: 'Ext.data.Model',
fields: ['challenge','username','response'],
proxy:
{
type: 'rest',
url: r25.ws+'login.xml',
reader:
{
url: r25.ws+'login.xml',
type: 'xml',
record: 'login'
}
}
});
storeLogin = new Ext.data.Store({
listeners: {
load: loginLoaded
},
autoLoad: true,
model: 'modelLogin'
});

Note: doesn't seem to matter if I initialize the store as a Store or an XmlStore or if I define the reader as type:xml or as reader: new Ext.data.XmlReader({}) at least as far as this issue goes.

Any ideas as to what I'm doing wrong, or is this a bug?

jsakalos
15 Jun 2011, 9:56 AM
If it works in Safari but not in Firefox I'm prone to say that it is a bug. Do you want me to move this thread to Bugs forum?

mrobinson
15 Jun 2011, 10:05 AM
If it works in Safari but not in Firefox I'm prone to say that it is a bug. Do you want me to move this thread to Bugs forum?

Please! I just wasn't sure if there was something that I was missing in the syntax being a neophyte to your products.

jsakalos
15 Jun 2011, 10:59 AM
Moved.

e.doychev
29 Sep 2011, 8:09 AM
I faced the same problem. It works perfect with Chrome (probably with Safari, too), but with Firefox and IE9 it behaves as described.

The problem disapear if I remove the namespace.

evant
29 Sep 2011, 5:21 PM
The problem boils down to the way browsers handle the getElementsByTagName method, which happens inside the DOMQuery selection. Let's say we have this:



Ext.require('Ext.data.*');
Ext.onReady(function(){
Ext.Ajax.request({
url: 'data.asp',
success: function(response) {
var root = response.responseXML.documentElement;
console.log(root.getElementsByTagName('login').length);
}
});
});


In FF & IE, we get 0. In Opera and WebKit, we get 1. This is a good read about the problem: http://www.zachleat.com/web/selecting-xml-with-javascript/

For the time being we still won't be supporting namespaced XML in the selector library, though I'll push it to the bug tracker, we may address it in the future.

e.doychev
30 Sep 2011, 5:57 AM
Thanks for the explanation evant.

Here is my workaround, written in Java. Just a function, which takes a XML as a string and by using several regualr expressions removes the namespace elements. It is not universal, but is good starting point for customization.



String removeNamespace(String xmlString) {
String regexp_xmlns = "\\s*(xmlns|xsi)[^\'\"]*=[\'\"][^\'\"]*[\'\"]";
String regexp_open = "<(\\w+:)";
String regexp_close = "<(\\/\\w+:)";



String result = xmlString.replaceAll(regexp_xmlns, "");

result = result.replaceAll(regexp_open, "<");

result = result.replaceAll(regexp_close, "</");



return result;
}


And be careful with the rgular expressions. I googled for the initial variants and then made some changes to suit my case. Probably they can be improved.

rmalhotr
18 Oct 2012, 12:39 PM
I am having the same issue and can't change the server side to remove the namespace. Is there a way to remove the namespace text from the xml when the response is received but before the reader attempts to read it?