php minixml详解
更新时间:2008年07月19日 19:49:23 作者:
MiniXML来自 Sourceforge ,参见:http://sourceforge.net/projects/minixml/,也有自己的官方网站: http://minixml.psychogenic.com/index.html.
使用方法如下,可以看到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.
$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.
相关文章
如何获知PHP程序占用多少内存(memory_get_usage)
想要知道编写的 PHP 脚本需要占用多少内存么?很简单,直接使用 PHP 查看当前分配给 PHP 脚本的内存的函数 memory_get_usage() 就可以了2012-09-09
最新评论