views:

50

answers:

1

Hi , I can't manage to get this Ext.data.XmlReader's CDATA field mapping to work.

 <script>
var store = new Ext.data.Store({
    url: '../data/data.xml',
    // specify a XmlReader  
    reader: new Ext.data.XmlReader({ 
    record: 'entry', 
    fields:[
            { name: 'field1', type: 'date', mapping:'field1'},  
            { name: 'field2', type: 'string', mapping:'field2'} 
           ] 
    }),
    listeners:{load:function(store,recs)
              {  //alert row1.field1 and row1.field2
                 var s = 'field1 = '+recs[0].get('field1') + '\nfield2 = '+recs[0].get('field2');
                 alert(s);
              }
     }
   });

store.load();
 </script>

And here's the XML contents in data.xml :

    <?xml version="1.0" encoding="UTF-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom"&gt; 
     <entry>  
       <field1>01/01/2006</field1>
       <field2>
           <![CDATA[
               <Comment>
                  Test
               </Comment>
             ]]>
       </field2>
      </entry>  
     </feed>

When store finished loading . The alert (from the listener) shows some thing like this:

field1 = Sun Jan 01 2006 00:00:00 GMT+0700 (ICT)
field2 = 

But I expected to see this :

field1 = Sun Jan 01 2006 00:00:00 GMT+0700 (ICT)
field2 = <Comment>
           Test
         </Comment>

These issue only happen in chrome and safari.it works with IE6.

How do I get the field2 node value (preferably, the solution works across major browsers), any suggestion ?

Thanks in advance.

Owat

+3  A: 

The <![CDATA[ start tag must start immediately after the XML tag with no space in between and the ]]> end tag must be followed immediately by the XML tag close, like this:

   <field2><![CDATA[
           <Comment>
              Test
           </Comment>
   ]]></field2>
Lukman
OMG , it really works! . Thankssss a lot.I've been fixing this for couple of days , never thought aboutspaces at all.
Will come back and give you a vote later. I tried it but I have noreputation. - -"Owat