探讨如何使用SimpleXML函数来加载和解析XML文档
网络编程 2021-07-05 09:49www.168986.cn编程入门
本篇文章是对使用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."
}
}
}
--------------------------------------------------------------------------------
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."
}
}
}
上一篇:深入php self与$this的详解
下一篇:解析dedeCMS验证码的实现代码
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程