dsvs50005 2011-12-23 11:42
浏览 10
已采纳

如何创建一个简单的php文件来生成XML结果

If I enter http://localhost/sitename?filter=city I would like to display all the cities in xml format

I would like the xml display in tag format like this

<city>
   <navi mumbai>
   <pune>
</city>
  • 写回答

2条回答 默认 最新

  • dphs48626 2011-12-23 11:50
    关注

    Here is sample php code , run this code with your link as filter as your condition

        Header("Content-type: text/xml"); 
        // get query string params
        $filter = $_GET['filter'];
    
        $xml = '';
    
        If ($filter == "city"){
            $xml = $xml . '<continent name="city">';
            $xml = $xml . '<city id="1">Navi Mumbai</city>';
            $xml = $xml . '<city id="2">Thane</city>';
            $xml = $xml . '<city id="3">Pune</city>';
            $xml = $xml . '</continent>';
        }else If ($filter == "country"){
            $xml = $xml . '<continent name="country">';
            $xml = $xml . '<country id="100">India</country>';
            $xml = $xml . '</continent>';
        }else If ($filter == "state"){
            $xml = $xml . '<continent name="state">';
            $xml = $xml . '<state id="300">Maharastra</state>';
            $xml = $xml . '</continent>';
        }else{
            $xml = $xml . '<continent name="none">';
            $xml = $xml . '<country id="0">no result found</country>';
            $xml = $xml . '</continent>';
        }
    
        // send xml to client
        echo( $xml );
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?