PHP扩展之XML操作(一)——SimpleXML
2014-11-07 00:00
1331 查看
一、简介及安装
SimpleXML 扩展提供了一个非常简单和易于使用的工具集,能将 XML 转换成一个带有一般属性选择器和数组迭代器的对象。
此扩展需要 libxml PHP 扩展。这表示需要使用 --enable-libxml ,尽管这将隐式完成因为 libxml 是缺省开启的。
需要PHP5及以上版本。
此扩展默认为启用,编译时可通过下列选项禁用: --disable-simplexml
二、使用示例
基本使用
Example #1 Include file example.php with XML string
<?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
<movie>
<title>PHP: Behind the Parser</title>
<characters>
<character>
<name>Ms. Coder</name>
<actor>Onlivia Actora</actor>
</character>
<character>
<name>Mr. Coder</name>
<actor>El ActÓr</actor>
</character>
</characters>
<plot>
So, this language. It's like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
<great-lines>
<line>PHP solves all my web problems</line>
</great-lines>
<rating type="thumbs">7</rating>
<rating type="stars">5</rating>
</movie>
</movies>
XML;
?>
SimpleXML 扩展提供了一个非常简单和易于使用的工具集,能将 XML 转换成一个带有一般属性选择器和数组迭代器的对象。
此扩展需要 libxml PHP 扩展。这表示需要使用 --enable-libxml ,尽管这将隐式完成因为 libxml 是缺省开启的。
需要PHP5及以上版本。
此扩展默认为启用,编译时可通过下列选项禁用: --disable-simplexml
二、使用示例
基本使用
Example #1 Include file example.php with XML string
<?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
<movie>
<title>PHP: Behind the Parser</title>
<characters>
<character>
<name>Ms. Coder</name>
<actor>Onlivia Actora</actor>
</character>
<character>
<name>Mr. Coder</name>
<actor>El ActÓr</actor>
</character>
</characters>
<plot>
So, this language. It's like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
<great-lines>
<line>PHP solves all my web problems</line>
</great-lines>
<rating type="thumbs">7</rating>
<rating type="stars">5</rating>
</movie>
</movies>
XML;
?>
相关文章推荐
- PHP扩展之XML操作(四)——XMLReader
- php用simplexml来操作xml
- PHP扩展之XML操作(五)——XMLWriter
- ***codeigniter操作xml(Simplexml第三方扩展)
- PHP SimpleXML 操作xml文档,添加元素 添加属性
- PHP扩展之XML操作(二)——XML解析器安装及概述
- php之SimpleXml操作xml
- Php利用simpleXML对xml操作
- php simpleXML操作xml的用法
- PHP扩展之XML操作(三)——XML解析器使用及相关函数
- php操作XML文件之SAX、simpleXML方式
- PHP XML操作的各种方法解析(比较详细)
- PHP操作xml
- ZZ [高端技术] PHP操作XML详解
- PHP操作XML
- php输出xml的实例(JavaScript操作XML实例)
- PHP对XML文件操作详细
- PHP通过DOM操作XML
- php下使用SimpleXML 处理XML 文件
- PHP操作XML作为数据库的类