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.

相关文章

php 的加密函数 md5,crypt,base64_encode 等使用介绍

不可逆的加密函数为:md5()、crypt() md5() 用来计算 MD5 哈稀。语法为:string md5(string str); crypt() 将字符串用 UNIX 的标准加...

PHP统一页面编码避免乱码问题

页面编码统一 MySQL数据库编码、html页面编码、PHP或html文件本身编码要全部一致。 1、MySQL数据库编码: 建立数据库时指定编码(如gbk_chinese_ci),建立...

php中的常用魔术方法总结

常用的魔术方法有:__Tostring ()  __Call()  __autoLoad()  __ clone()  __GET() ...

PHP7新增运算符用法实例分析

PHP7新增运算符用法实例分析

本文实例讲述了PHP7新增运算符用法。分享给大家供大家参考,具体如下: NULL 合并运算符 其实是三元运算符的改造,减少的代码量 //原先的做法 //$lig = isset($_...

php在项目中寻找代码的坏味道(综艺命名)

php在项目中寻找代码的坏味道(综艺命名)

漫画篇 查字典   这个是我比较习惯的方式,打开字典,把中文放进去,看它能给我什么好的名字。             &nb...