我是靠谱客的博主 俏皮小鸽子,这篇文章主要介绍通过XPath查询XML中的数据,现在分享给大家,希望可以做个参考。

一 代码

复制代码 "; } } } ?> 查询XML文件 select_message(iconv("GB2312","UTF-8","$_POST[Action]")); } ?>
请输入标题名称:   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php class Message_XML extends DomDocument{ private $Root; public function __construct() { parent:: __construct(); $this->load("Rss.xml");} public function select_message($Action){ $Root = $this->documentElement; $xpath = new DOMXPath($this); $node_Record = $xpath->query("//item[title='$Action']"); for($i=0;$i<$node_Record->length;$i++){ $g=0; foreach($node_Record->item($i)->childNodes as $node){ $field[$g]=iconv("UTF-8","GB2312",$node->textContent); $g++; } print "<table width='750' height='75' border='1' cellpadding='1' cellspacing='1' bordercolor='#FFFFFF' bgcolor='#0099FF'> <tr> <td width='126' height='25' align='center'><span class='STYLE_select5'>标题</span></td> <td width='611'><input name='title' type='text' id='title' size='50' value='$field[0]'></td> </tr> <tr> <td height='25' align='center'><span class='STYLE_select5'>链接地址</span></td> <td><input name='link' type='text' id='link' size='60' value='$field[1]'></td> </tr> <tr> <td height='25' align='center'><span class='STYLE_select5'>内容摘要</span></td> <td><textarea name='description' cols='80' rows='5' id='description'>$field[2]</textarea></td> </tr> </table>"; } } } ?> <title>查询XML文件</title> <style type='text/css'> <!-- .STYLE_select5 {font-size: 13px; font-weight: bold; color: #FFFFFF; } --> </style> <style type="text/css"> <!-- body,td,th { font-size: 13px; } a:link { text-decoration: none; } a:visited { text-decoration: none; } a:hover { text-decoration: none; } a:active { text-decoration: none; } .STYLE2 {font-size: 18px} --> </style> <body> <table width=750 height=35 border=1 cellpadding=3 cellspacing=1 bordercolor="#FFFFFF" bgcolor="#0099FF"> <form name="form1" method="post" action="index.php"> <tr> <td height=35 align="center"><span class="STYLE_select5">请输入标题名称:</span> <input name="Action" type="text" id="Action"> &nbsp;&nbsp;<input type="submit" name="Submit" value="提交"> </td> </tr> </form> <?php if($_POST[Submit]==true){ $HawkXML = new Message_XML; $HawkXML->select_message(iconv("GB2312","UTF-8","$_POST[Action]")); } ?> </table> </body>

 

二 运行结果

 
  • 大小: 6 KB
  • 查看图片附件

最后

以上就是俏皮小鸽子最近收集整理的关于通过XPath查询XML中的数据的全部内容,更多相关通过XPath查询XML中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部