探討如何使用SimpleXML函數(shù)來(lái)加載和解析XML文檔
更新時(shí)間:2013年06月07日 12:05:22 作者:
本篇文章是對(duì)使用SimpleXML函數(shù)來(lái)加載和解析XML文檔進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
大量SmipleXML函數(shù)可用來(lái)加載和解析大量XML文檔。
--------------------------------------------------------------------------------
1.simpleXML_load_file()函數(shù)來(lái)加載指定的XML文件到對(duì)象。如果加載文件時(shí)遇到問(wèn)題,則返回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);
?>
輸出結(jié)果:
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()函數(shù)來(lái)加載指定的XML文件到對(duì)象。如果加載文件時(shí)遇到問(wèn)題,則返回FLASE。例:
book.xml文件:
復(fù)制代碼 代碼如下:
<?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文件:
復(fù)制代碼 代碼如下:
<?php
$xml=simplexml_load_file("book.xml");echo "<pre>";
var_dump($xml);
?>
輸出結(jié)果:
復(fù)制代碼 代碼如下:
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."
}
}
}
相關(guān)文章
PHP json_encode中文亂碼問(wèn)題的解決辦法
這篇文章介紹了PHP json_encode中文亂碼問(wèn)題的解決辦法,有需要的朋友可以參考一下2013-09-09Thinkphp結(jié)合ajaxFileUpload實(shí)現(xiàn)異步圖片傳輸示例
這篇文章主要給大家介紹了利用Thinkphp結(jié)合ajaxFileUpload實(shí)現(xiàn)異步圖片傳輸?shù)姆椒?,文中給出了詳細(xì)的示例代碼,對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-03-03PHP編程實(shí)現(xiàn)的TCP服務(wù)端和客戶端功能示例
這篇文章主要介紹了PHP編程實(shí)現(xiàn)的TCP服務(wù)端和客戶端功能,結(jié)合實(shí)例形式分析了php基于socket實(shí)現(xiàn)TCP服務(wù)器端與客戶端通信功能的相關(guān)配置、定義與使用技巧,需要的朋友可以參考下2018-04-04php無(wú)需編譯安裝openssl擴(kuò)展的實(shí)現(xiàn)方法
下面小編就為大家分享一篇php無(wú)需編譯安裝openssl擴(kuò)展的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03