<?php/**
 * @author nosunday
 * @copyright 2007
 */class MMClass{
private $strFilePath="";
private $dom;
function setFilePath($FilePath){
$this->strFilePath=$FilePath;
}
function getFilePath(){
return $this->strFilePath;
}
function openfile($FilePath=""){
if($FilePath<>"")
{
$this->strFilePath=$FilePath;
}
if(file_exists($this->strFilePath))
{
$this->dom=new DOMDocument;
$this->dom->load($this->strFilePath);
}
else{
$this->dom=new DOMDocument('1.0', 'utf8');
$nodeRoot=$this->dom->createElement("root","");
$attrRoot=$nodeRoot->setAttribute("index",0);
$this->dom->appendChild($nodeRoot);
$this->dom->save($this->strFilePath);
}
}
function createClass($strClassName,$strComment="",$strParent=0){
$nodeClass=$this->dom->createElement("class");
$nodeClass->setAttribute("name",$strClassName);
$nodeClass->setAttribute("comment",$strComment);
$nodeID=$this->getIndex()+1;
$nodeClass->setAttribute("ID",$nodeID);
$this->setIndex($nodeID);
$nodeRoot=$this->dom->getElementsByTagName("root");
foreach($nodeRoot as $nodeRot){
 $nodeRot->appendChild($nodeClass);
}

$this->dom->save($this->strFilePath);
}
function getIndex(){
$nodeRoot=$this->dom->getElementsByTagName("root");
foreach($nodeRoot as $nodeRot){
return (int)$nodeRot->getAttribute("index");
}
}
function setIndex($Index){
$nodeRoot=$this->dom->getElementsByTagName("root");
foreach($nodeRoot as $nodeRot){
$nodeRot->setAttribute("index",$Index);
}
}
}
$cls=new MMClass;
$cls->openfile("tezt.xml");
$cls->createClass("测试")?>运行后:
Warning: DOMDocument::load() [function.DOMDocument-load]: Start tag expected, '<' not found in file:///D%3A/usr/webroot/test/tezt.xml, line: 2 in D:\usr\webroot\test\xmltest.php on line 25