欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php minixml详解

程序员文章站 2022-04-11 18:56:01
使用方法如下,可以看到minixml的使用,与activelink-php-xml-package-0.4.0相比,更加符合使用习惯,也更加的简单.  $xmld...
使用方法如下,可以看到minixml的使用,与activelink-php-xml-package-0.4.0相比,更加符合使用习惯,也更加的简单. 

$xmldoc = new minixmldoc(); 
$xmlroot =& $xmldoc->getroot(); 
$childelement =& $xmlroot->createchild(\'achild\'); 
$childelement->attribute(\'name\', \'annie\'); 
$childelement->text(\'this element has attributes and children, such as this\'); 
$image =& $childelement->createchild(\'image\'); 
$image->attribute(\'location\', \'http://psychogenic.com/image.png\'); 
$childelement->text(\'image and little\'); 
$orphan =& $xmldoc->createelement(\'song\'); 
$orphan->text(\'tomorrow, tomorrow\'); 
$childelement->appendchild($orphan); 
print $xmldoc->tostring(); 

添加一个子元素,有两种方式,第一种是直接该结点createchild,第二种是先xmldoc先createelement,然后,该结点在appendchild. 

最后打印出来的结果是: 
<?xml version="1.0"?> 
<achild name="annie" eyes="#0000ff" hair="#ff0000"> 
this element has attributes and children, such as this 
<image location="http://psychogenic.com/image.png" /> 
image and little 
<song> tomorrow, tomorrow </song> 
</achild> 


可以很明显的看得出,minixml的使用方法是非常简单的,尤其是对于简单的保存数据的xml文件,更是如此,详细可以看minixml提供的例子.此处不详说. 

========================================================================= 

解析 

minixml文件结构是: 
minixml.inc.php 
------classes 
-----------doc.inc.php element.inc.php node.inc.php treecomp.inc.php 

详细的api解释说明,在官方网站上有介绍: http://minixml.psychogenic.com/api.html.