探讨如何使用SimpleXML函数来加载和解析XML文档
大量smiplexml函数可用来加载和解析大量xml文档。
--------------------------------------------------------------------------------
1.
simplexml_load_file()函数来加载指定的xml文件到对象。如果加载文件时遇到问题,则返回flase。例:
book.xml文件:
<?xml version="1.0" standalone="yes"?>
<library>
<book>
<title>pride and prejudice</title>
<author gender="female">jane austen</author>
<description>jane austen's most popular work.</description>
</book>
<book>
<title>the conformist</title>
<author gender="male">alberto moravia</author>
<description>alberto moravia's classic psyhcological novel.</description>
</book>
<book>
<title>the sun also rises</title>
<author gender="male">ernest hemingway</author>
<description>the masterpiece that launched hemingway's career.</description>
</book>
</library>
php文件:
<?php
$xml=simplexml_load_file("book.xml");echo "<pre>";
var_dump($xml);
?>
输出结果:
object(simplexmlelement)#1 (1) {
["book"]=>
array(3) {
[0]=>
object(simplexmlelement)#2 (3) {
["title"]=>
string(19) "pride and prejudice"
["author"]=>
string(11) "jane austen"
["description"]=>
string(32) "jane austen's most popular work."
}
[1]=>
object(simplexmlelement)#3 (3) {
["title"]=>
string(14) "the conformist"
["author"]=>
string(15) "alberto moravia"
["description"]=>
string(46) "alberto moravia's classic psyhcological novel."
}
[2]=>
object(simplexmlelement)#4 (3) {
["title"]=>
string(18) "the sun also rises"
["author"]=>
string(16) "ernest hemingway"
["description"]=>
string(49) "the masterpiece that launched hemingway's career."
}
}
}
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
-
-
-
-
-
管理后台无限级菜单
管理后台菜单遍历很久就想做一个通用的管理后台出来,一直太懒没做,今天开始粗略搞了一下,只是先把框架搭建好,菜单栏...
[阅读全文]
-
桥接模式学习总结
桥接模式引言假如一个系统需要加入报表模块,主要的开发点是数据的获取和报表的显示方式。数据的获取可能是从系统数据库...
[阅读全文]
网友评论