1. #1
    Ext User
    Join Date
    Dec 2010
    Location
    Buenos Aires, Argentina
    Posts
    1
    Vote Rating
    0
    humbert is on a distinguished road

      0  

    Default Problem with XML Reader

    Problem with XML Reader


    Hello everyone. I'm new on JavaScript coding, and I´m having a trouble with the XMLReader. Maybe I'm doing somethig wrong, but i'm trying to retrieve data from an XML file. I readed in som thread that i have to use a web server to make this work, so i installed Xampp in my PC and moved all the sencha files into it. I started this aplication using the ajax example, to know what sources to include into it. Here's the code, it's very simple but it isn't working:

    Code:
    <html>
    <head>
        <content-type: "text/xml">
        <link rel="stylesheet" href="../../resources/css/sencha-touch.css" type="text/css">
        <script type="text/javascript" src="../../sencha-touch.js"></script>
        <script type="text/javascript" src="index.js"></script>
        <script type="text/javascript">
    //I create the model 
    Ext.regModel('User', {
        fields: ['id', 'name', 'email']
    });
    //I start a var using the model structure
    var user = Ext.ModelMgr.create(
       {
       id: '4',
       name: 'Conan',
       email: 'conan@hotmail.com',
       }, 
       'User');
    //I create the Store using the Model
    var store = new Ext.data.Store(
     {
        model: 'User',
    // I create the Store's proxy 
     proxy: {
             type: 'ajax',
             url : 'http://localhost/sencha/examples/ajax/users.xml',
    //   I create the xml reader to consume the xml file.   
             reader: {
                  type: 'xml',
              root: 'users',
                  record: 'user',
               }
          }
     }); 
    // I call the method load to fill the store with the xml data.   
    store.load();
    // Just to test the store I add the User var into it
    store.insert(4,'User');
    // I write the quantity of records in the store.
    document.write(store.data.getCount());
    // This always returns just one, the one i added with the insert() method.
        </script>
    <title>Prueba XML</title>
    </head>
    <body>
    </body>
    </html>
    And this is the xml file users.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <users>
    <user>
     <id>1</id>
     <name>Ed Spencer</name>
     <email>ed@sencha.com</email>
    </user>
    <user>
     <id>2</id>
     <name>Abe Elias</name>
     <email>abe@sencha.com</email>
    </user>
    </users>
    Please, can anyone tell me what's wrong??

    Thanks.-

    Humberto Araoz.-

  2. #2
    Touch Premium Member
    Join Date
    Oct 2010
    Posts
    27
    Vote Rating
    0
    doncoleman is on a distinguished road

      0  

    Default


    Try this:

    index.html
    Code:
    <html>
    <head>
        <link rel="stylesheet" href="sencha-touch.css" type="text/css">
        <script type="text/javascript" src="sencha-touch-debug.js"></script>
        <script type="text/javascript" src="app.js"></script>
    	<title>Prueba XML</title>
    </head>
    <body>
    </body>
    </html>
    app.js
    Code:
    /*global Ext*/
    Ext.setup({
        onReady: function() {
    
            Ext.regModel('User', {
                fields: [
                    {name: 'id', type: 'int'},    
                    {name: 'name', type: 'string'},    
                    {name: 'email', type: 'string'}
                ]
            });
            
            var store = new Ext.data.Store({
                storeId: 'userStore',
                model: 'User',
                proxy: {
                    type: 'ajax',
                    url: 'users.xml',
                    reader: {
                        type: 'xml',
                        root: 'user'
                    }
                }
            });
            
            store.load();
                    
            var panel = new Ext.Panel({
               fullscreen: true,
               items: [ 
                   {
                       xtype: 'list',
                       store: store,
                       itemTpl: "\"{name}\" &lt;{email}&gt;",
                       singleSelect: true
                   }
               ] 
            });        
        }
    });

  3. #3
    Sencha User gaurav.k's Avatar
    Join Date
    Nov 2011
    Location
    Bangalore, India
    Posts
    11
    Vote Rating
    0
    gaurav.k is on a distinguished road

      0  

    Default Problem not solved.

    Problem not solved.


    @doncoleman
    I have posted my problem on 3 different threads, but I din't get any solution or suggestion for that.

    I am facing the same problem and tried your suggestion but din't worked.
    With all the efforts I make one thing is in common, the error!!
    and thats :

    XMLHttpRequest cannot load file://localhost/Users/gauravkeshre/Sites/Sancha-touch Workspace/ALS_SHG/app/xml/sample.xml?_dc=1320988507322&limit=25. Origin null is not allowed by Access-Control-Allow-Origin.
    If your problem is solved. Please share the solutions.

    Thank you

Similar Threads

  1. XML Reader problem
    By saravanan.sbm in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 22 Apr 2009, 2:09 AM
  2. XML Reader record problem
    By nahawand in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 21 Apr 2009, 5:46 AM
  3. XML Reader / Grid Problem
    By Tony Mariella in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 25 Jul 2008, 9:39 AM
  4. XML Reader Problem
    By Tony Mariella in forum Ext 2.x: Help & Discussion
    Replies: 14
    Last Post: 24 Apr 2008, 8:32 AM

Thread Participants: 2