Results 1 to 2 of 2

Thread: Xml woes

  1. #1
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    18

    Default Xml woes

    Hi All I have XML as below

    Code:
    <search>
        <results hitCount="8">
            <result pnum="22" eid="71a5db25-b0a5-4872-aeb3-5a69d698aa2c" name="04/19/2011">
                killers BYLARRYMcSHANE DAILYNEWSSTAFFWRITER THEUPCOMINGROYALwedding is a <b>royal</b> pain for British security
            </result>
            <result pnum="21" eid="71a5db25-b0a5-4872-aeb3-5a69d698aa2c" name="04/19/2011">
                sBig Island based on a3-night stayat<b>Royal</b> Kona Resort. Caribbean valid for travel thru8/31/11; must be booked
            </result>
            <result pnum="59" eid="71a5db25-b0a5-4872-aeb3-5a69d698aa2c" name="04/19/2011">
                , <b>ROYALS</b> 3(10): Pinch- hitter Shelley Duncans RBI double sparkedafour-run10thinningandvisiting Cleveland
            </result>
            <result pnum="75" eid="71a5db25-b0a5-4872-aeb3-5a69d698aa2c" name="04/19/2011">
                Reina del Sur (ss) The First 48 (cc) Blue Planet: Seas of Life (cc) <b>Royally</b> Mad (N) (cc) Family Affair
            </result>
            <result pnum="65" eid="71a5db25-b0a5-4872-aeb3-5a69d698aa2c" name="04/19/2011">
                BLUEJAYS WHITESOX(6:40) atRAYS TWINS(7:05) atORIOLES ANGELS(8:05) atRANGERS INDIANS(8:10) at<b>ROYALS</b> REDSOX(10:05) at
            </result>
            <result pnum="63" eid="71a5db25-b0a5-4872-aeb3-5a69d698aa2c" name="04/19/2011">
                . Pablos Cuevas,Uruguay,7-5, 3-6, 6-4. GrandPrixdeSARLaPrincesse LallaMeryem YESTERDAYSRESULTS At<b>Royal</b>
            </result>
            <result pnum="64" eid="71a5db25-b0a5-4872-aeb3-5a69d698aa2c" name="04/19/2011">
                -5 3-5 4-4 2-3 Indians 7, <b>Royals</b> 3(10) Cleveland Sizemorecf A.Cabrerass Choorf AB RH RBI BB SO Avg. 51
            </result>
            <result pnum="69" eid="71a5db25-b0a5-4872-aeb3-5a69d698aa2c" name="04/19/2011">
                Louie'sLass MajorDixie RuleTheDay DeDanann RomanMaiden ForRealToo Fairly<b>Royal</b> 5th Horses 4-GrandCaptain 7
            </result>
        </results>
    </search>
    And a model as

    Code:
    var modsearchinfo = Ext.regModel('searchinfo', {
       fields: [
             { name: 'pnum', mapping: '@pnum', type: 'string' },
             { name: 'eid', mapping: '@eid', type: 'string' },
             { name: 'name', mapping: '@name', type: 'string' },
             
             
          ]
    });
    I can pick up the values in the mapping but I want to pick up the values inside the brackets, ie first row - "killers BYLARRYMcSHANE DAILYNEWSSTAFFWRITER THEUPCOMINGROYALwedding is a <b>royal</b> pain for British security"

    I have tried adding a result field without mapping but its a different level down so isnt picking up

    Please help, please
    Last edited by jratcliff; 2 Jul 2011 at 1:19 PM. Reason: added code tags and some indentation so I could read the xml and the code

  2. #2
    Sencha - Services Team
    Join Date
    Mar 2007
    Location
    Foristell, MO
    Posts
    1,120

    Default

    Try this override for XmlReader which just adds an extra check to see if the key (mapping) is '$self' and if so, it just graps the value directly from the root node.

    Code:
    Ext.override(Ext.data.XmlReader, {
            
        createAccessor: function() {
            var selectValue = function(key, root, defaultValue){
                var node = (key === '$self') ? root : Ext.DomQuery.selectNode(key, root),
                    val;
                if (node && node.firstChild) {
                    val = node.firstChild.nodeValue;
                }
                return Ext.isEmpty(val) ? defaultValue : val;
            };
    
            return function(key) {
                var fn;
    
                if (key == this.totalProperty) {
                    fn = function(root, defaultValue) {
                        var value = selectValue(key, root, defaultValue);
                        return parseFloat(value);
                    };
                }
    
                else if (key == this.successProperty) {
                    fn = function(root, defaultValue) {
                        var value = selectValue(key, root, true);
                        return (value !== false && value !== 'false');
                    };
                }
    
                else {
                    fn = function(root, defaultValue) {
                        return selectValue(key, root, defaultValue);
                    };
                }
    
                return fn;
            };
        }()
    
    })
    Then, add a field for your results and map it to '$self'
    Code:
    {field : 'results', mapping: '$self'}
    Jack Ratcliff
    Sencha Inc, Green bleeding Senchan

    How to report a bug:
    https://www.sencha.com/forum/showthr...o-report-a-bug

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •