PDA

View Full Version : Problem loading data into XmlStore



fallenrayne
24 Aug 2009, 10:26 PM
Hi all,

I am having issues getting my XmlStore to read the data that I am passing it. With firebug I am able to see that the xml is being loaded, just never parsed. I have no control over the xml format.

XML:

<?xml version="1.0" encoding="UTF-8"?>
<search xmlns="">
<site value="Essential Magic" url="http://EssentialMagic.com/" />
<searchinfo date="Monday, August 24, 2009" results="4540" />
<searchresults>
<card name="Abandon Hope"
castcost="X1B"
spelltype="Sorcery"
creaturetype=""
power="0"
toughness="0"
cardset="Tempest"
color="Black"
rarity="Uncommon"
artist="Alan Pollack"
numberowned="1"
>
<rulestext>
Choose and discard X cards: Look at target opponent's hand and choose X of those cards. That player discards the chosen cards.
</rulestext>
<flavortext>
As Gerrard's form vanished into the maw of trees, Hanna mouthed a silent plea, mourning a crushed dream.
</flavortext>
</card>

<card name="Abbey Gargoyles"
castcost="2WWW"
spelltype="Summon"
creaturetype="Gargoyle"
power="3"
toughness="4"
cardset="5th Edition"
color="White"
rarity="Uncommon"
artist="Christopher Rush"
numberowned="1"
>
<rulestext>
Flying, protection from red
</rulestext>
<flavortext>
“They don't move, do they?”

“Only for the wrong sort of people.”

“Are we the wrong sort of people?”
</flavortext>
</card>
</searchresults>
</search>

XmlStore:

store = new Ext.data.XmlStore({
storeId:'myStore',
url:'inventory.xml',
autoLoad:true,
record:'card',
fields:[{
name:'Name',
mapping:'@name'
}]
});
alert(store.getTotalCount());

Any help would be greatly appreciated. I have been beating my head against this for 2 hours now and nothing I try seems to work and I can't seem to find any answers in the forums or API.

fallenrayne
25 Aug 2009, 11:22 AM
As a quick note, I realize that getTotalCount() will not return anything due to the fact that I am not getting the totalRecords. I was not really using that line for debugging, it was a hold over from earlier attempts. I was using FireBug to see that there were no records in the store.

steffenk
25 Aug 2009, 11:48 PM
i fear you have to read this custom xml by your own.

Have a look to the svn cmmit log with an example:
http://extjs.com/blog/2009/08/10/ext-js-30-be-outstanding/

Condor
26 Aug 2009, 1:19 AM
You can easily read this XML with an XmlReader.

Your problem is that you can't evaluate the data before the store is loaded.

Setting autoLoad:true or calling load() will only send a request to the server. You still have to wait for the server response before you can access the data.

You can use the load callback function or a load event handler for this, e.g.

store.on('load', function(){
alert(store.getTotalCount());
});

fallenrayne
26 Aug 2009, 4:36 AM
Condor,

While that was exactly the problem when I was testing with a smaller set of data, there is still a slight problem. Is there a limit to the size of data that the XMLStore can read in? The main XML is about 16000 records, 96745 lines. If I scale it down to 2 records it works but when I try to load the whole thing I just get the alert immediately with 0 records.

If need be I could probably do this in chunks, but I was hoping that the store would be able to handle that much data.

Thanks for the smack to the side of the head though, much appreciated.

fallenrayne
26 Aug 2009, 4:42 AM
Actually, nevermind. I just figured out that the XML this site is providing is not well-formed. I hadn't tried opening it directly into Firefox before and as soon as I tried I got errors. So that would be why the small subset works, I grabbed records that were fine, it blows up a few hundred lines down.

Thanks again, I just need to figure out how to fix this XML now. :)

csoon1
27 Aug 2009, 8:03 AM
You can easily read this XML with an XmlReader.

Your problem is that you can't evaluate the data before the store is loaded.

Setting autoLoad:true or calling load() will only send a request to the server. You still have to wait for the server response before you can access the data.

You can use the load callback function or a load event handler for this, e.g.

store.on('load', function(){
alert(store.getTotalCount());
});

So how can the loaded data at the store be accessed at some latter time? Example I want to access the records? I tried playing with this before but I was only able to access the records within the callback but I was unsuccessful outside of it.

csoon1
27 Aug 2009, 8:05 AM
You can easily read this XML with an XmlReader.

Your problem is that you can't evaluate the data before the store is loaded.

Setting autoLoad:true or calling load() will only send a request to the server. You still have to wait for the server response before you can access the data.

You can use the load callback function or a load event handler for this, e.g.

store.on('load', function(){
alert(store.getTotalCount());
});

So how can the data/records be accessed after being loaded at the store? I tried playing with the data within the callback but I had been unsuccessful accessing it outside of callback.