PDA

View Full Version : XmlReader returns 'undefined' - please help spot what I am missing ;-)



RobWilson
4 Feb 2010, 8:31 AM
Hi,

I have a rather simple XML document that I am trying to get ExtJS to parse using an XmlReader, but when I try to read the values out, they are all undefined.

Could someone please highlight what I'm missing? :D
Code:



Ext.getCmp('login-form').getForm().submit( {
success: function (form,action) {
var xml = action.response.responseXML;
var record = parseLoginCredentials(xml);
var token = record.token;
var userid = record.userid;
},
.
.

function parseLoginCredentials(document) {
var myReader = new Ext.data.XmlReader({
record: "logincredentials"
}, Ext.data.Record.create([
{name: 'token', mapping:'token'},
{name: 'userid', mapping: 'userid'}]));
return myReader.readRecords(document);
}
Xml:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<logincredentials>
<token>tPin44qie3ACyH0...d8616007wU</token>
<success>true</success>
<userId>33</userId>
</logincredentials>
I am wondering whether Ext is expecting some sort of 'root' node?

Thanks,
Rob.

RobWilson
7 Feb 2010, 1:16 PM
I don't suppose anyone has had any thoughts on this? :-?

Cheers,
Rob.

evant
7 Feb 2010, 4:07 PM
I don't get why you're using a reader there. If you're just parsing the xml, why not just use the built in browser methods to grab the data you need?

RobWilson
7 Feb 2010, 11:46 PM
I don't get why you're using a reader there. If you're just parsing the xml, why not just use the built in browser methods to grab the data you need?

I was keen to get into the habit of using the ExtJS functions instead - even for simple returned data. Your point is valid, I will probably parse it like you say, however, I would like to understand why this doesn't work first.

Thanks for your reply.