I can't get it to work either. Is there a simple example somewhere?
I can't get it to work either. Is there a simple example somewhere?
Figured it out some days ago, here's a pretty simple example for the rest of you:
It doesn't do anything interesting, just load the xml then print the name of the first author.
To access the nested elements use something like this
store.getAt(0).books().each(function(book){
console.log(book);
});
index.js
XML:Code:var App = new Ext.Application({
name: 'Books',
useLoadMask: true,
launch: function () {
Ext.regModel('Book', {
idProperty: 'name',
fields: [
{ name: 'name', type: 'string' },
],
belongsTo: 'Author',
proxy: {
type: 'memory',
reader: {
type: 'xml',
root: 'books',
record: 'book'
}
}
});
Ext.regModel('Author', {
idProperty: 'name',
fields: [
{ name: 'name', type: 'string' },
],
hasMany: [
{
model : 'Book',
name: 'books',
}
]
});
store = new Ext.data.Store({
model: 'Author',
proxy: {
type: 'ajax',
url: './books.xml',
reader: {
type: 'xml',
record: 'author',
root: 'authors'
}
}
});
store.load();
content = new Ext.form.FormPanel({
items:[
{
xtype:'textfield',
name: 'name',
label:'Author: '
}
]
});
Books.views.viewport = new Ext.Panel({
fullscreen: true,
layout: 'card',
items: [
content
]
});
//log the books to console to prove they were loaded
setTimeout(function() {
content.load(store.getAt(0));
store.getAt(0).books().each(function(book){
console.log(book);
});
}, 1000);
}
});
I could have tidied the code up a bit, but I'm working on a project and don't have time for that.Code:<authors>
<author>
<name>Author 1</name>
<books>
<book>
<name>Book</name>
</book>
<book>
<name>Book2</name>
</book>
</books>
</author>
<author>
<name>Author 2</name>
<books>
<book>
<name>Book3</name>
</book>
<book>
<name>Book4</name>
</book>
</books>
</author>
</authors>
is it possible such a struct to parce ?
<xxx> <author name="Author 1"> <book name="Book1"/> <book name="Book2"/> </author> <author name="Author 2"> <book name="Book1"/> <book name="Book2"/> </author> </xxx>
With 2.0 just around the corner, I've added this to its backlog to make sure this happens. Almost all of our efforts are focused on 2.x at the moment so it should be a relatively simple thing to drop in
Please help, I am very depressed, I am already late on a SenchaTouch project and it must be finished by tomorrow. I have spent all weekend working on a nested XML feed and I cannot for the life of me get anything to return from the nested sections.
I was hoping you could please please please give a complete working example?
I have searched and searched but cannot find a single example anywhere.
Taking your example further, I have this:
Ext.regModel('Book',{
fields:[
{name:'bookname',type:'string'},
{name:'pages',type:'int'},
{name:'score',type:'int'}
],
proxy: {
type: 'memory',
reader: {
type: 'xml',
root: 'books',
record: 'book'
}
}
});
Ext.regModel('User',{
fields:[
{name:'userid',type: 'int'},
{name:'username',type:'string'},
{name:'books',type:'string'}
],
//hasMany: {model: 'Book', name: 'books'},
proxy: {
type: 'ajax',
url : urlRizlabProjects,
reader: {
type: 'xml',
root: 'users',
record: 'user'
}
}
});
You are free to completely change everything below but this is roughly what I normally do:
var storage7 = new Ext.data.Store({
model: 'User',
listeners: {
datachanged: function(){
storage7.each(function(rec){
alert(rec.get('username')); //this bit works
//but how do I access the books here please?????????????????????????
});
}
}
});
thank you so much - I have tried to find information about memory records but have got nothing, plus a very long list of pages with people asking about nested xml.
Must have been feeling really tired, and didn't properly try out bobbaluba's example above - it works! I will bookmark this url and post it whenever I see other lost soul's trying to get this working
Am I correct to assume that parsing the following XML isn't possible with Sencha Touch 1.0? Seeing as the <section> tags and <production> tags don't have an element surrounding them, which would correspond to the root parameter when you create an XMLReader?
Code:<?xml version="1.0" encoding="iso-8859-1" ?>
<production>
<productiondate>2011-09-18</productiondate>
<updated>2011-09-19 13:03:00</updated>
<section>
<header>September 2011</header>
<production>
<header>Profit</header>
<prodvalue>1451</prodvalue>
<plandiff>-20</plandiff>
</production>
<production>
<header>Hours</header>
<prodvalue>1384</prodvalue>
<plandiff>-55</plandiff>
</production>
<production>
<header>Cost</header>
<prodvalue>1203</prodvalue>
<plandiff>-147</plandiff>
</production>
</section>
<section>
<header>Development</header>
<production>
<header>KA2</header>
<prodvalue>0.0</prodvalue>
<plandiff>-1.7</plandiff>
</production>
<production>
<header>KA3</header>
<prodvalue>1.2</prodvalue>
<plandiff>-0.4</plandiff>
</production>
<production>
<header>KK2</header>
<prodvalue>10.8</prodvalue>
<plandiff>-0.4</plandiff>
</production>
<production>
<header>KK3</header>
<prodvalue>13.3</prodvalue>
<plandiff>-1.2</plandiff>
</production>
<production>
<header>KK4</header>
<prodvalue>13.9</prodvalue>
<plandiff>-1.5</plandiff>
</production>
<production>
<header>KS</header>
<prodvalue>1.7</prodvalue>
<plandiff>1.7</plandiff>
</production>
<production>
<header>SA</header>
<prodvalue>0.0</prodvalue>
<plandiff>0.0</plandiff>
</production>
<production>
<header>SK</header>
<prodvalue>12.3</prodvalue>
<plandiff>1.3</plandiff>
</production>
<production>
<header>MK3</header>
<prodvalue>11.1</prodvalue>
<plandiff>0.6</plandiff>
</production>
<production>
<header>BUV</header>
<prodvalue>11.3</prodvalue>
<plandiff>0.4</plandiff>
</production>
<production>
<header>ANR</header>
<prodvalue>8.2</prodvalue>
<plandiff>2.4</plandiff>
</production>
</section>
<section>
<header>Ores</header>
<production>
<header>Sweden</header>
<prodvalue>72.6</prodvalue>
<plandiff>-3.3</plandiff>
</production>
<production>
<header>Norway</header>
<prodvalue>56.5</prodvalue>
<plandiff>7.3</plandiff>
</production>
</section>
<section>
<header>Train</header>
<production>
<header>Sweden</header>
<prodvalue>6</prodvalue>
<plandiff>-4</plandiff>
</production>
<production>
<header>Norway</header>
<prodvalue>4</prodvalue>
<plandiff>-1</plandiff>
</production>
</section>
</production>
The hasMany associations keep giving only one result for the child data for XML. Isn't this issue still solved with ST 1.1? Using all the ideas given here, I get only one association data.