php minixml详解

yipeiwu_com6年前PHP代码库
使用方法如下,可以看到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="/zb_users/upload/202003/4txxn0yavcv.jpg" /> 
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.

相关文章

Thinkphp框架开发移动端接口(2)

接着上一篇介绍Thinkphp框架开发移动端接口(1),另外我们还可以通过ThinkPHP实现移动端访问自动切换主题模板,这样也可以做到移动端访问 ThinkPHP的模板主题机制,如果只...

php如何解决无法上传大于8M的文件问题

开发一个文件上传共享网站,曾想使用下面的代码实现文件上传的功能: 复制代码 代码如下: <form enctype="multipart/form-data" action="ad...

解决PHP 7编译安装错误:cannot stat ‘phar.phar’: No such file or directory

解决PHP 7编译安装错误:cannot stat ‘phar.phar’: No such file or directory

前言 最近因为工作需要要使用PHP 7,所以从网上找教程进行安装, 结果编译没问题, 安装的时候报了错误。 错误如下 cp -pR -f phar.phar /usr/local/p...

PHP中错误与异常的日志记录用法分析

本文分析了PHP中错误与异常的日志记录用法。分享给大家供大家参考,具体如下: 提到 Nginx + PHP 服务的错误日志,我们通常能想到的有 Nginx 的 access 日志、err...

php使用Jpgraph绘制简单X-Y坐标图的方法

php使用Jpgraph绘制简单X-Y坐标图的方法

本文实例讲述了php使用Jpgraph绘制简单X-Y坐标图的方法。分享给大家供大家参考。具体实现方法如下: <?php include ("src/jpgraph.p...