Home > php教程 > php手册 > 探讨如何使用SimpleXML函数来加载和解析XML文档

探讨如何使用SimpleXML函数来加载和解析XML文档

WBOY
Release: 2016-06-13 11:50:10
Original
917 people have browsed it

大量SmipleXML函数可用来加载和解析大量XML文档。
--------------------------------------------------------------------------------
1.simpleXML_load_file()函数来加载指定的XML文件到对象。如果加载文件时遇到问题,则返回FLASE。例:
book.xml文件:

复制代码 代码如下:




 
  Pride and Prejudice
  Jane Austen
  Jane Austen's most popular work.
 

 
  The Conformist
  Alberto Moravia
  Alberto Moravia's classic psyhcological novel.
 

 
  The Sun Also Rises
  Ernest Hemingway
  The masterpiece that launched Hemingway's career.
 



php文件:

复制代码 代码如下:


$xml=simplexml_load_file("book.xml");echo "

";<br>var_dump($xml);<br>?><br><br>输出结果:<br><p class="codetitle"><span style="CURSOR: pointer" onclick="doCopy('code2415')"><u>复制代码</u></span> 代码如下:</p><p class="codebody" id="code2415"><br>object(SimpleXMLElement)#1 (1) {<br>  ["book"]=><br>  array(3) {<br>    [0]=><br>    object(SimpleXMLElement)#2 (3) {<br>      ["title"]=><br>      string(19) "Pride and Prejudice"<br>      ["author"]=><br>      string(11) "Jane Austen"<br>      ["description"]=><br>      string(32) "Jane Austen's most popular work."<br>    }<br>    [1]=><br>    object(SimpleXMLElement)#3 (3) {<br>      ["title"]=><br>      string(14) "The Conformist"<br>      ["author"]=><br>      string(15) "Alberto Moravia"<br>      ["description"]=><br>      string(46) "Alberto Moravia's classic psyhcological novel."<br>    }<br>    [2]=><br>    object(SimpleXMLElement)#4 (3) {<br>      ["title"]=><br>      string(18) "The Sun Also Rises"<br>      ["author"]=><br>      string(16) "Ernest Hemingway"<br>      ["description"]=><br>      string(49) "The masterpiece that launched Hemingway's career."<br>    }<br>  }<br>}<br></p><br>

Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template