1. #1
    Ext User
    Join Date
    Oct 2009
    Posts
    6
    Vote Rating
    0
    binaryfever is on a distinguished road

      0  

    Default Multiple XML child nodes and XMLReader

    Multiple XML child nodes and XMLReader


    Hi. I have been searching the forums and docs for the last couple of days and am having a hard time figuring out how to do this with XMLReader. I am attempting to access all the presenters from the following xml.

    PHP Code:
    <results>
    <
    result>
    <
    title>Monthly Review Getting Started</title>
    <
    mediaUrl></mediaUrl>
    <
    mediaAbstract>Getting Started</mediaAbstract>
    <
    durationHours>0</durationHours>
    <
    durationMinutes>16</durationMinutes>
    <
    category>Meetings</category>
    <
    accessLevel>engineering</accessLevel>
    <
    presenters>
    <
    presenter>
    <
    lastName>doe</lastName>
    <
    firstName>john</firstName>
    <
    biography/>
    </
    presenter>
    <
    presenter>
    <
    lastName>roberts</lastName>
    <
    firstName>bob</firstName>
    <
    biography/>
    </
    presenter>
    </
    presenters>
    </
    result>
    </
    results
    Here is the js.
    PHP Code:
    var ds = new Ext.data.Store({
                        
    remoteSorttrue,
                        
    proxy: new Ext.data.HttpProxy({
                            
    url'/wsproxy_media.pl'
                        
    }),
                        
    reader: new Ext.data.XmlReader({
                            
    root'results',
                            
    totalProperty'@total',
                            
    record'result',

                        }, [
                            {
    name'title'mapping'title'},
                            {
    name'url'mapping'mediaUrl'},
                            {
    name'abstract'mapping'mediaAbstract'},
                            {
    name'hours'mapping'durationHours'},
                            {
    name'minutes'mapping'durationMinutes'},
                            {
    name'category'mapping'category'},
                            {
    name'presenter'mapping'presenters > presenter > firstName'}
                            ]),

                        
    baseParams: {q:qstart0limit:pageSize}
                    });
                    
                    
    // Custom rendering Template for the View
                    
    var resultTpl = new Ext.XTemplate(
                        
    '<tpl for=".">',
                        
    '<div class="yui-g" style="padding-top: 5px;">',  
                          
    '<div class="yui-u first" style="width: 70%;">',
                            
    '<div style="border-right: 1px dotted #333333; padding-right: 5px; padding-left: 5px;">',
                              
    '<p><a href="{url}" class="autoIconMEDIA" target="_blank">{title}</a></p>',
                              
    '<p>{abstract}</p>',
                            
    '</div>',
                          
    '</div>',
                         
    '<div class="yui-u" style="width: 30%;">',
                            
    '<div style="padding-left: 10px;">',
                              
    '<div>Date: {datePosted}</div>',
                              
    '<div>Duration: {hours} hours {minutes} minutes</div>',
                              
    '<div>Presenters: {presenter}</div>',
                              
    '<div>Category: <a href="#" onclick="searchViaLink(\'{category}\');">{category}</a></div>',
                            
    '</div>',
                          
    '</div>',    
                        
    '</div>',
                        
    '<div class="horizontal-dots-gray"></div>',
                        
    '</tpl>'
                    
    ); 
    I know that this only displays the presenters first name because I am just walking down the xml and I believe its grabbing the last presenter. How do I get all of them? I have seen some solutions that require editing the XMLReader source. Unfortunately I am in a large corporation that uses ext js so I don't have access to the source. Any help would be really appreciated.

  2. #2
    Sencha User
    Join Date
    Sep 2009
    Posts
    81
    Vote Rating
    0
    alupuli is on a distinguished road

      0  

    Default


    A function can be refered while mapping.
    like,
    Code:
     
    {name: 'presenter', mapping: function(node){
         var rslt = ""; 
         var names = Ext.DomQuery.select('presenters/presenter',node);
     
         for(var i=0; i < ids.length; i++){
            rslt+=Ext.DomQuery.select('firstName',names[i])[0].firstChild.nodeValue +","; 
        }
         return rslt;
    }}
    Could n't get exact working code. Needs to work on it.

  3. #3
    Sencha User
    Join Date
    Mar 2010
    Posts
    25
    Vote Rating
    0
    mshepherd is on a distinguished road

      0  

    Default


    Does this work? I can't seem to get the function to work. Anyone have an example of a node with multiple children?

  4. #4
    Ext User
    Join Date
    Oct 2009
    Posts
    6
    Vote Rating
    0
    binaryfever is on a distinguished road

      0  

    Default


    Quote Originally Posted by mshepherd View Post
    Does this work? I can't seem to get the function to work. Anyone have an example of a node with multiple children?
    Actually I ended up creating another reader an using that in the regular reader.

    Code:
    ...
    var tagReader = new Ext.data.XmlReader({
    				record:'tag',
    				fields: [
    				{name:'id', mapping:'@id'},
    				{name:'name', mapping:'@name'}
    				]
    			});
    
     ds = new Ext.data.Store({
    ....
    reader: new Ext.data.XmlReader({
    					record: 'result',
    					idProperty: 'asset > @id',
    					totalRecords: '@total',
    						fields: [
    							{name: 'id', mapping: 'asset > @id'},
    							{name: 'title', mapping: 'title'},
    							{name: 'datePosted', mapping: 'datePosted'},
    							{name: 'assetAbstract', mapping: 'assetAbstract'},
    							{name: 'platformUrl', mapping: 'platformUrl'},
    							{name: 'platformType', mapping: 'platformType'},
    							{name: 'ratingTotal', mapping: 'ratings > @ratingTotal'},
    							{name: 'ratingSum', mapping: 'ratings > @ratingTotalSum'},
    							{name: 'views', mapping: 'views'},
    							{name: 'totalComments', mapping: 'comments > @commentTotal'},
    							{name: 'tags', convert:function(v,n){
    								return tagReader.readRecords(n).records;
    								}
    							}
    ....

Thread Participants: 2