概述
一 代码
<?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">
<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>
二 运行结果
最后
以上就是俏皮小鸽子为你收集整理的通过XPath查询XML中的数据的全部内容,希望文章能够帮你解决通过XPath查询XML中的数据所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复