php minixml详解

yipeiwu_com5年前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.

相关文章

php基于session锁防止阻塞请求的方法分析

本文实例讲述了php基于session锁防止阻塞请求的方法。分享给大家供大家参考,具体如下: 说明: 这是一篇参考国外网站http://konrness.com/php5/how-to-...

php 正确解码javascript中通过escape编码后的字符

这是很久以前收集的一个,不知道谁写的了,但经过测试没有问题~ JavaScript代码 复制代码 代码如下: function phpUnescape($escstr) { preg_m...

PHP开发实现快递查询功能详解

PHP开发实现快递查询功能详解

背景:不久前,设计实现了京东api的功能,发现如果换了其它快递再重新设计,岂不是会浪费太多的时间,所以选个第三方提供的快递API是最为合理的,下面给出快递鸟和快递100的设计实现。 一....

php字符比较函数similar_text、strnatcmp与strcasecmp用法分析

本文实例讲述了php字符比较函数similar_text、strnatcmp与strcasecmp用法。分享给大家供大家参考。具体如下: ① similar_text() 函数计算两个字...

PHP实现普通hash分布式算法简单示例

本文实例讲述了PHP实现普通hash分布式算法。分享给大家供大家参考,具体如下: <?php /* * 普通hash分布式算法 * @param $key * @...