2011-10-20 11 views
-1

私はPHPで働いています。私はテーブルから自分の結果のxmlファイルを作りたい。私は、PHPでREST APIを作成したい。だから私はSLIMフレームワークを使用してREST APIを作成しています。xmlはPHPで作成されていません

これは私のコードです:

<?php 
    include('connect.php'); 

    header('Content-type: text/xml'); 

    header('Content-type: application/json'); 

     // Include the Slim library 
     require 'Slim/Slim.php'; 

     // Instantiate the Slim class 
     $app = new Slim(); 

     // Create a GET-based route 
     $app->get('/', function() { 

     echo "Pericent is working on Campus Concierge..."; 
     }); 



    $app->get('/schools', function() { 

    $rs = mysql_query("SELECT * FROM school") or die ("invalid query"); 


    //count the no. of columns in the table 
    $fcount = mysql_num_fields($rs); 

    //you can choose any name for the starting tag 
    //echo "$pass"; 
    echo ("<result>"); 
    while($row = mysql_fetch_array($rs)) 
    { 

    echo ("<tablerow>"); 
    for($i=0; $i< $fcount; $i++) 
    { 
    $tag = mysql_field_name($rs, $i); 
    echo ("<$tag>".htmlentities($row[$i]). "</$tag>"); 
    } 
    echo ("</tablerow>"); 
    } 
    echo ("</result>"); 
    }); 


     // Ready the routes and run the application 
     $app->run(); 
    ?> 

しかし、私の結果はこのようなものです:

1Pericent2Wilfred3KV54SentAnslem5AnandCollege 

<>にあるすべてのものが表示されないことを意味します。私がやっている間違いは何か助けてください。前もって感謝します。

+1

これはブラウザでテストしていますか?なぜXMLが必要なのか、なぜJSONヘッダーを設定していますか? –

+0

」から完全な出力を投稿してください。 – CodeCaster

+0

出力ページのページソースを表示します。 –

答えて

0
header('Content-type: text/xml'); 

header('Content-type: application/json'); 

適切なコンテンツ・タイプが

application/rss+xmlまたはapplication/rdf+xmlまたはapplication/atom+xml

ブラウザは、多くの場合、タグをふるいにする必要があります。

0

ちょうどあなたが

header("Content-Type: plain/text"); 

header('Content-type: text/xml'); 

header('Content-type: application/json'); 

を交換してJSONとXML

を使用している場合、私はあなただけとにかくテストの目的のために、今、それを出力していると仮定プレーンテキストを使用します。

+0

先生、あなたは私に正しく答えました。しかし、私はXMLを作成したいです。だから私はモバイルアプリケーションで私の次のプログラミングの概念のためにそのXMLを使用することができます。 –

+0

xmlを作成しています。あなたはそれを見ることはできません。 –

関連する問題