PDA

View Full Version : XML Reader Help



jaquin
27 Sep 2010, 6:33 PM
Hi all,

I am new to developing and also new to sencha touch. I was tinkering with some examples and would like to ask some help with regards to xml reader. I cant seem to read the xml file.

here's my code:

####### js file ############

Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function() {

Ext.regModel('Node', {
fields : [
{name : 'sessionId', type : 'string'}
]
});

var store = new Ext.data.Store({
model : 'Node',
proxy : {
type : 'ajax',
url : 'test.xml',
reader : {
type : 'xml',
root : 'resp'
}
},
listeners : {
single : true,
datachanged : function() {
Ext.getBody().unmask();
store.each(function(rec) {
network.push({
sessionId : rec.get('sessionId'),
});
});
}
}
});
store.read();

}
});



######## test.xml ##########

<?xml version="1.0" encoding="UTF-8" ?>
- (http://www.sencha.com/forum/) <resp status="ok">
<sessionId>rest-5268020154968643962</sessionId>

</resp>


here is the error when i am trying to debug using chrome:

XMLHttpRequest cannot load file:///C:/Documents%20and%20Settings/user/Desktop/phone%20gap%20+%20sencha%20touch/sencha-touch-beta-0.95/sencha-touch-beta-0.95/examples/xml%20read/test.xml?_dc=1285640547346. Origin null is not allowed by Access-Control-Allow-Origin.


to those that will reply. Thank you in advance:)

evant
27 Sep 2010, 6:46 PM
You need to run it through a web server.

jaquin
27 Sep 2010, 7:02 PM
I tried running it through a web server but still doesn't show the SessionId. I tried debugging it with chrome but it shows no error. Could you tell me what I am doing wrong?


Again Thanks.

evant
27 Sep 2010, 7:05 PM
Well, for one the case doesn't match on sessionId.

jaquin
27 Sep 2010, 10:16 PM
Well, for one the case doesn't match on sessionId.

I fixed my code now but I still cannot get the sessionId? Any suggestions in improving my code?

Thanks.

kortovos
28 Sep 2010, 12:32 AM
I have the same problem. I found out that it is because you are calling 'resp' which is the top most tag. For some reason beyond my understanding a store cannot use the top most tag as a record/root.

I am currently searching for a solution, but so far nothing. If anyone knows a solution for this, please post it here.

Update: I have found a solution. Just wrap another tag around your result before returning it to the store. Then you can use 'resp' as the record/root


$return = $client->$_POST['action']($postvars);
$return = str_replace("<resp","<d><resp",$return);
$return = str_replace("</resp>","</resp></d>",$return);
echo($return);

jaquin
28 Sep 2010, 5:13 PM
Update: I have found a solution. Just wrap another tag around your result before returning it to the store. Then you can use 'resp' as the record/root


$return = $client->$_POST['action']($postvars);
$return = str_replace("<resp","<d><resp",$return);
$return = str_replace("</resp>","</resp></d>",$return);
echo($return);


Thanks. This worked for me.

jordans
28 Sep 2010, 5:33 PM
Thank you for sharing