-
17 Apr 2009 8:08 AM #1
Simple XML parsing with ExtJS
Simple XML parsing with ExtJS
Hello,
I get an XML via Ajax request and I want to display some tag contents in an alert.
I only found solutions which store the xml data in a Ext.data.Store but I'm not searching something like this.
Example :
Naturally this doesn't works but I hope u know what I mean!!Code:Ext.Ajax.request({ url : './php/FileCarrier.php' , method: 'GET', success: function ( result, request ) { Ext.Msg.alert(result.responseText.get("title")[0]); } });
Thank you!!
Casbar
-
17 Apr 2009 8:17 AM #2
Take a look at Ext.data.Connection. The response also has a responseXML field which you can process with Ext.DomQuery.
PHP Code:var conn = new Ext.data.Connection;
conn.request({
url: myURL,
callback: function(options, success, response)
{
if (success)
{
var dq = Ext.DomQuery;
var xml = response.responseXML;
var node = dq.selectNode('nodename', xml);
}
}
});
-
20 Apr 2009 2:35 AM #3
Scuse me I am a beginner...
how i can run through the "element" elements and display the content of the other tags?
my xml looks like this:
Code:<elements> <element> <title>sfdsf</title> <name>dfddfs</name> </element> <element> <title>bla</title> <name>rtz</name> </element> <element> <title>xsd</title> <name>awe</name> </element> </elements>
-
20 Apr 2009 3:06 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
You can do everything with DomQuery (as shown above), but this is starting to look like something for a Store with an XmlReader.
Code:var store = new Ext.data.Store({ url: 'somefile.xml', reader: new Ext.data.XmlReader({ record: 'element', fields: ['title', 'name'] }) });
-
20 Apr 2009 6:36 AM #5
Yes I already used a store, but I don't know how I can simple display the data for example in an alert or something like this.
In every example I saw something like for example
but there isn't any way to walk through a store with a loop or something like this...Code:var fe_DataView = new Ext.DataView({ store: fe_store, ...
is it right?
What I have to to is to put, in this case, the titles in div-tags on the body!
Anyone any idea? Is it possible to it with a store?
casbar
-
20 Apr 2009 6:44 AM #6Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
You could use a DataView with a tpl:
or you could display it directly:Code:var tpl = new Ext.XTemplate( '<tpl for=".">', '<h1>{title}</h1>', '<h1>{name}</h1>', '</tpl>' );
(of course you need to wait for the store to load first)Code:var tpl = new Ext.XTemplate( '<tpl for=".">', '<h1>{data.title}</h1>', '<h1>{data.name}</h1>', '</tpl>' ); tpl.append(Ext.getBody(), store.getRange());
-
20 Apr 2009 8:02 AM #7
Sorry Condor but it still not working!!
I try a lot of versions...
What I wrote:
There isn't any error, and if i display in an alert "store.getRange()" there are only three Objects which is true but it not displays anything!!Code:var store = new Ext.data.Store({ url: './php/FileCarrier.php?dir=/Desktop/', autoLoad: true, reader: new Ext.data.XmlReader({ record: 'element', fields: ['directory', 'filename', 'type', 'created', 'last_edit', 'size', 'show_name', 'icon'] }) }); store.on('load', function(store, records, options) { var tpl = new Ext.XTemplate( '<tpl for=".">', '<h1>{filename}</h1>', '<h1>{show_name}</h1>', '</tpl>' ); tpl.append(Ext.get("woos-desktop"), store.getRange()); });
-
20 Apr 2009 9:57 AM #8Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
The <tpl for> will iterate over all records, but a record doesn't have filename and show_name properties. The inner data object has.
That is why you should use:
Code:var tpl = new Ext.XTemplate( '<tpl for=".">', '<h1>{data.filename}</h1>', '<h1>{data.show_name}</h1>', '</tpl>' );
-
20 Apr 2009 10:15 AM #9
-
20 Apr 2009 8:53 PM #10Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Yes, sorry about that. It should be:
Code:var tpl = new Ext.XTemplate( '<tpl for=".">', '<h1>{values.data.filename}</h1>', '<h1>{values.data.show_name}</h1>', '</tpl>' );


Reply With Quote