2011-07-02 15 views

答えて

2

私はSencha Touchの新機能ですが、XMLを読み込んで表示することができます。問題は、クロスドメインxmlにアクセスできないということでした(PhoneGapそこには方法があるので)、私はすべてのファイルを同じ場所に置き、私のサーバー上のPHPスクリプトを使ってXMLを解析します(順番にローカルに保ちます)。

<!DOCTYPE html> 
<html> 
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
     <title>XML Example</title> 
     <script src="../sencha-touch-debug.js" type="text/javascript"> 
     </script> 
     <link href="../resources/css/sencha-touch.css" rel="stylesheet" type="text/css"> 
     <script type="text/javascript"> 
      new Ext.Application({ 
       name: 'xmlexample', 
       launch: function(){ 
        Ext.regModel('Profile', { 
         fields: ['nobea','nobeb','nodec','noded'] //etc... 
        }); 

        this.stores.profiles = new Ext.data.Store({ 
         model: 'Profile', 
         autoLoad:true, 
         implicitIncludes: true, 
         proxy: { 
          type: 'ajax', 
          url : 'http://www.yourwebsite.co/php/xmlparse.php?url=http://externalxmllink', 
          reader: { 
           type : 'xml', 
           root : 'profile', 
           record: 'profile' 
          } 
         } 
        }); 
       var productTpl = new Ext.XTemplate(
        '<tpl for=".">', 
         '<div class="data">{nobea}</div>', 
         '<div class="data">{nobeb}</div>', 
       '<div class="data">{nobec}</div>', 
         '<div class="data">{nobed}</div>', 
        '</tpl>' 
       );  
       new Ext.Panel({ 
        fullscreen: true, 
        items: new Ext.DataView({ 
         store: this.stores.profiles, 
         tpl: productTpl, 
         itemSelector: 'product-selected' 
         //other config goes here 
        }) 
       }); 
      } 
     });   
     </script> 
    </head> 
    <body> 
    </body> 
</html> 

だからサンプルXMLファイルは次のようになります。以下の例を参照してくださいここで

<?xml version="1.0" encoding="utf-8"?> 
<profile> 
<nodea>text</nodea> 
<nodeb>text</nodeb> 
<nodec>text</nodec> 
<noded>text</noded> 
</profile> 

とすること

<?php 
// Set your return content type 
header('Content-type: application/xml'); 

// Website url to open 
//$daurl = 'http://YOURXMLLINK'; 
$daurl = $_GET['url']; 

// Get that website's content 
$handle = fopen($daurl, "r"); 

// If there is something, read and return 
if ($handle) { 
    while (!feof($handle)) { 
     $buffer = fgets($handle, 4096); 
     echo $buffer; 
    } 
    fclose($handle); 
} 
?> 

ホープ、このことができますxmlparse.php :)

+0

ちょっと、上記のプログラムでパラメータを渡す方法を教えてください... – himanshu

0
です

あなたはいくつかのタイプミスがありました(ノードの代わりにnobed)

これは動作します:

<!DOCTYPE html> 
<html> 
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
     <title>XML Example</title> 
     <script src="../touch/sencha-touch.js" type="text/javascript"></script> 
     <link rel="stylesheet" href="../touch/resources/css/sencha-touch.css" /> 
     <script type="text/javascript"> 
      new Ext.Application({ 
       name: 'xmlexample', 
       launch: function(){ 
        Ext.regModel('Profile', { 
         fields: ['nodea','nodeb','nodec','noded'] //etc... 
        }); 

        this.stores.profiles = new Ext.data.Store({ 
         model: 'Profile', 
         autoLoad:true, 
         implicitIncludes: true, 
         proxy: { 
          type: 'ajax', 
          url : 'data.xml', 
          reader: { 
           type : 'xml', 
           root : 'profile', 
           record: 'profile' 
          } 
         } 
        }); 
       var productTpl = new Ext.XTemplate(
        '<tpl for=".">', 
         '<div class="data">{nodea}</div>', 
         '<div class="data">{nodeb}</div>', 
       '<div class="data">{nodec}</div>', 
         '<div class="data">{noded}</div>', 
        '</tpl>' 
       );  
       new Ext.Panel({ 
        fullscreen: true, 
        items: new Ext.DataView({ 
         store: this.stores.profiles, 
         tpl: productTpl, 
         itemSelector: 'product-selected' 
         //other config goes here 
        }) 
       }); 
      } 
     });   
     </script> 
    </head> 
    <body> 
    </body> 
</html> 
関連する問題