PHP增加xml节点

class addnode extends DomDocument
{
function __construct()
{
   parent::__construct();
}
function add($url,$caption,$width,$height,$po)
{
   $image=$this->createElement("image");
   $url=$this->createElement("url",$url);
   $caption=$this->createElement("caption",$caption);
   $width=$this->createElement("width",$width);
   $height=$this->createElement("height",$height);
   $image->appendChild($url);
   $image->appendChild($caption);
   $image->appendChild($width);
   $image->appendChild($height);
   //$this->documentElement->appendChild($image);  appendChild只是添加到最后
   //$y=$this.getElementsByTagName("image")[0];
   $this->documentElement->insertBefore($image,$po);
}
}
//==================================写入xml函数==============================
function addimage($url,$caption,$width,$height)
{
$dom=new addnode();
$dom->load("gallery.xml");
$po=$dom->getElementsByTagName("image");
$po=$po->item(0);
$dom->add($url,$caption,$width,$height,$po);
$dom->save("gallery.xml");
}
//==================================END写入xml函数============================