一 代码
<?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>
二 运行结果
![](https://i-blog.csdnimg.cn/blog_migrate/67bae03179d91bbc0fc53ce95ac6d02b.png)