zoukankan      html  css  js  c++  java
  • XML文档的PHP程序查询代码

    PHP文档:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
    http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <link rel="shortcut icon" href="1.ico" />
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <style type="text/css">
                .tableStyle{border-collapse: collapse;border-color:#008000;color:blue;90%;table-layout: fixed;}
                th{background-color:#5F9EA0;}
            </style>
        </head>
        <body>
            <center><h1>XML文档的PHP查询程序</h1></center>
            <hr/>
            <?php
                function getNodeVal(&$myNode,$tagName,$i){  //$myNode:节点对象,$tagName:节点名称,$i:节点项目
                    return $myNode->getElementsByTagName($tagName)->item($i)->nodeValue;
                }
    
                function getValue($node_1,$node_2,$i,$directory){
                        /*$node:XML第一节节点名
                        *$node_1:第二节节点名
                        *$i:查询的节点位置
                        *$directory:XML文件路径
                        */
                        $xmldoc=new DOMDocument();
                        $xmldoc->load($directory);
                        $deploy=$xmldoc->getElementsByTagName($node_1);
                        $array[0]=$deploy->length;
                        $deploy_1=$deploy->item($i);
                        $array[1]=getNodeVal($deploy_1,$node_2,0); //获得XML信息
                        return $array;
                }
            ?>
        <center>
        <table border="" class="tableStyle">
            <tr>
                <th width="20%">名字</th><th width="20%">年龄</th><th width="60%">介绍</th>
            </tr>
            <?php
                $array_show=getValue("学生","名字",0,"class.xml");
                for($i=0;$i < $array_show[0];$i++){
            ?>
      <tr>     <td width="20%" align="center" valign="middle">
          <?php $array_show=getValue("学生","名字",$i,"class.xml");echo $array_show[1];?>
        </td>     <td width="20%" align="center" valign="middle">
          <?php $array_show=getValue("学生","年龄",$i,"class.xml");echo $array_show[1];?>
        </td>     <td width="60%" align="center" valign="middle">
          <?php $array_show=getValue("学生","介绍",$i,"class.xml");echo $array_show[1];?>
        </td>   </tr> <?php } ?> </table> </center> </body> </html>

     XML文档:

    <?xml version="1.0" encoding="UTF-8"?>
    <班级>
        <学生>
            <名字>唐僧</名字>
            <年龄>800</年龄>
            <介绍>西天取经人!</介绍>
        </学生>
        <学生>
            <名字>孙悟空</名字>
            <年龄>500</年龄>
            <介绍>唐僧大徒弟!</介绍>
        </学生>
        <学生>
            <名字>猪八戒</名字>
            <年龄>300</年龄>
            <介绍>唐僧二徒弟!</介绍>
        </学生>
        <学生>
            <名字>沙和尚</名字>
            <年龄>200</年龄>
            <介绍>唐僧三徒弟!</介绍>
        </学生>
        <学生>
            <名字>白龙马</名字>
            <年龄>100</年龄>
            <介绍>唐僧的坐骑!</介绍>
        </学生>
    </班级>
  • 相关阅读:
    Python综合学习 python入门学习 python速成
    博客建设
    文献搜索方法
    Mac效率工具集合
    Mac High Sierra 三步搞定安装Eclipes
    Mac High Sierra一步搞定Mysql安装
    Mac中使用的建模工具/流程图制作
    R语言的安装以及入门
    (一)linux基本的操作命令
    小程序canvas简单电子签名
  • 原文地址:https://www.cnblogs.com/qingsong/p/4909068.html
Copyright © 2011-2022 走看看