这是一个xml 解析类
class Message_XML extends DOMDocument
{
const file_name = "e:/myphp/xmldom/xml/message.xml";
private $root; //根节点
private $PageNo; //当前页
private $allNum; //记录总数
private $PageSize; //页大小
private $allPages; //总页数
public function __construct()
{
parent::__construct();
if(!file_exists(self::file_name))
{
$xmlStr = "
$this -> loadXML($xmlStr);
$this -> save(self::file_name);
}else{
$this -> load(self::file_name);
}
$this -> root = $this -> documentElement;
$this -> get_pagemsg();
}
//得到页信息
private function get_pagemsg()
{
$this -> PageSize = 3; //页大小
$allNode = $this -> getElementsByTagName("record");
$this -> allNum = $allNode -> length; //记录总数
$this -> allPages = ceil($this -> allNum / $this -> PageSize); //总页数
$this -> PageNo = $_GET["PageNo"];
if($this -> PageNo PageNo))
{
$this -> PageNo = 1;
}else if($this -> PageNo > $this -> allPages){
$this -> PageNo = $this -> allPages;
}
$this -> PageNo = (int)$this -> PageNo;
}
//显示留言
public function show_message()
{
$start_num = ($this -> PageNo - 1) * $this -> PageSize; //记录开始数
$end_num = $start_num + $this -> PageSize - 1; //记录结束数
$allNode = $this -> getElementsByTagName("record");
$i = 0;
foreach($allNode as $v)
{
if($i >= $start_num && $i
{
$autoid = $v -> getElementsByTagName("autoid") -> item(0) -> nodeValue;
$subject = $v -> getElementsByTagName("subject") -> item(0) -> nodeValue;
$content = $v -> getElementsByTagName("content") -> item(0) -> nodeValue;
$str = "