1. #1
    Ext User
    Join Date
    Mar 2009
    Posts
    102
    Vote Rating
    0
    casbar is on a distinguished road

      0  

    Question 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 :

    Code:
    Ext.Ajax.request({
            url : './php/FileCarrier.php' , 
            method: 'GET',
            success: function ( result, request )
            { 
                Ext.Msg.alert(result.responseText.get("title")[0]);
            }
        });
    Naturally this doesn't works but I hope u know what I mean!!
    Thank you!!

    Casbar

  2. #2
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750
    Vote Rating
    7
    fay will become famous soon enough fay will become famous soon enough

      1  

    Default


    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({
      
    urlmyURL
      
    callback: function(optionssuccessresponse)
      { 
        if (
    success)
        {
          var 
    dq Ext.DomQuery;
          var 
    xml response.responseXML;
              
          var 
    node dq.selectNode('nodename'xml); 
        }
      }
    }); 

  3. #3
    Ext User
    Join Date
    Mar 2009
    Posts
    102
    Vote Rating
    0
    casbar is on a distinguished road

      0  

    Default


    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>

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,251
    Vote Rating
    73
    Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold

      1  

    Default


    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']
      })
    });

  5. #5
    Ext User
    Join Date
    Mar 2009
    Posts
    102
    Vote Rating
    0
    casbar is on a distinguished road

      0  

    Default


    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

    Code:
    var fe_DataView = new Ext.DataView({
            store: fe_store,
    ...
    but there isn't any way to walk through a store with a loop or something like this...
    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

  6. #6
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,251
    Vote Rating
    73
    Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold

      0  

    Default


    You could use a DataView with a tpl:
    Code:
    var tpl = new Ext.XTemplate(
    	'<tpl for=".">',
    	'<h1>{title}</h1>',
    	'<h1>{name}</h1>',
    	'</tpl>'
    );
    or you could display it directly:
    Code:
    var tpl = new Ext.XTemplate(
    	'<tpl for=".">',
    	'<h1>{data.title}</h1>',
    	'<h1>{data.name}</h1>',
    	'</tpl>'
    );
    tpl.append(Ext.getBody(), store.getRange());
    (of course you need to wait for the store to load first)

  7. #7
    Ext User
    Join Date
    Mar 2009
    Posts
    102
    Vote Rating
    0
    casbar is on a distinguished road

      0  

    Default


    Sorry Condor but it still not working!!
    I try a lot of versions...
    What I wrote:

    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());
            
        });
    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!!

  8. #8
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,251
    Vote Rating
    73
    Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold

      0  

    Default


    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>'
    );

  9. #9
    Ext User
    Join Date
    Mar 2009
    Posts
    102
    Vote Rating
    0
    casbar is on a distinguished road

      0  

    Default


    data is not defined !!

  10. #10
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,251
    Vote Rating
    73
    Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold

      0  

    Default


    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>'
    );

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar