1. #1
    Sencha User
    Join Date
    Feb 2011
    Location
    Bangalore, India
    Posts
    10
    Vote Rating
    0
    noor.mujeeb is on a distinguished road

      0  

    Default Reading XML content with CDATA

    Reading XML content with CDATA


    Hello,

    I am trying to read an XML document with content like below. You can notice that the first record (<H>) set contains the header names for the grid. The second record set (<Data/R>) has the data for the grid.

    My problem is I dont know how to use EXT JS to read this type of data and render to the grid. Also, the data has CDATA attribute in it and I am not sure how to read this type of data using EXT JS XMLReader. Will appreciate any form of help. Thank you all.


    <Result count='3' PS='200' SC='3' SO='1'>
    <H>
    <D PID='3' WD='100' CID='-1'><![CDATA[Interaction ID]]></D>
    <D PID='119' WD='130' CID='101'><![CDATA[Team]]></D>
    <D PID='3' WD='100' CID='-1'><![CDATA[Interaction ID]]></D>
    <D PID='5' WD='22' CID='1'><![CDATA[Interaction state]]></D>
    </H>
    <Data>
    <R>
    <D><![CDATA[1]]></D>
    <D><![CDATA[1]]></D>
    <D><![CDATA[1]]></D>
    <D><![CDATA[Open]]></D>
    </R>
    <R>
    <D><![CDATA[2]]></D>
    <D><![CDATA[1]]></D>
    <D><![CDATA[2]]></D>
    <D><![CDATA[Open]]></D> ...............


    Regards,
    Noor

  2. #2
    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


    CDATA can be a bit tricky.

    You'll have to use something like:
    Code:
    var reader = new Ext.data.XmlReader({
      record: 'Result > Data > R',
      fields: [
        {name: 'interactionId1', convert: function(v, n) {
          var data = Ext.DomQuery.selectNode('> D:nth(1)', n);
          for(var i = 0, len = data.childNodes.length; i < len; i++){
            var childNode = data.childNodes[i];
            if(childNode.nodeType == 4){
              return parseInt(childNode.textContent || childNode.innerText || '', 10);
            }
          }
          return null;
        }},
        {name: 'team', convert: function(v, n) {
          var data = Ext.DomQuery.selectNode('> D:nth(2)', n);
          for(var i = 0, len = data.childNodes.length; i < len; i++){
            var childNode = data.childNodes[i];
            if(childNode.nodeType == 4){
              return parseInt(childNode.textContent || childNode.innerText || '', 10);
            }
          }
          return null;
        }},
        {name: 'interactionId2', convert: function(v, n) {
          var data = Ext.DomQuery.selectNode('> D:nth(1)', n);
          for(var i = 0, len = data.childNodes.length; i < len; i++){
            var childNode = data.childNodes[i];
            if(childNode.nodeType == 4){
              return parseInt(childNode.textContent || childNode.innerText || '', 10);
            }
          }
          return null;
        }},
        {name: 'interactionState', convert: function(v, n) {
          var data = Ext.DomQuery.selectNode('> D:nth(4)', n);
          for(var i = 0, len = data.childNodes.length; i < len; i++){
            var childNode = data.childNodes[i];
            if(childNode.nodeType == 4){
              return childNode.textContent || childNode.innerText || '';
            }
          }
          return null;
        }}
      ]
    });

  3. #3
    Sencha User
    Join Date
    Feb 2011
    Location
    Bangalore, India
    Posts
    10
    Vote Rating
    0
    noor.mujeeb is on a distinguished road

      0  

    Default


    Hello Codor,

    Thank you for your reply. I tried your code but its not working. I am not sure why there is a "return null" at the end of every for loop. So, I commented it and tried, but still no luck.. Any other suggestion.?

    Thanks again for your reply.

    Regards,
    Noor

  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

      0  

    Default


    Is that the exact XML structure? Do the record and field selectors ('Result > Data > R' and '> D:nth(1)') correctly locate the record and the field?

Similar Threads

  1. XmlReader : help with normalizing CDATA
    By psylux in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 23 Mar 2009, 8:47 AM
  2. Replies: 0
    Last Post: 16 Jul 2008, 5:50 AM
  3. What is ![CDATA[ needed for?
    By Chamster in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 10 Jul 2008, 4:34 AM
  4. Reading SWF file content from Server
    By tinakonda in forum Ext 2.x: Help & Discussion
    Replies: 18
    Last Post: 7 Jul 2008, 3:26 PM
  5. CDATA content not displaying in Grid and XMLDataModel
    By xsolonix in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 13 Jan 2007, 2:38 PM

Thread Participants: 1

Tags for this Thread

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