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

前端之家收集整理的这篇文章主要介绍了探讨如何使用SimpleXML函数来加载和解析XML文档前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

大量SmipleXML函数可用来加载和解析大量XML文档。
--------------------------------------------------------------------------------
1.

<FONT style="COLOR: #ff0000">simpleXML_load_file()

函数来加载指定的XML文件到对象。如果加载文件时遇到问题,则返回FLASE。例:
book.xml文件
<div class="codetitle"><a style="CURSOR: pointer" data="82152" class="copybut" id="copybut82152" onclick="doCopy('code82152')"> 代码如下:
<div class="codebody" id="code82152">
<?xml version="1.0" standalone="yes"?>


Pride and Prejudice
<author gender="female">Jane Austen
Jane Austen's most popular work.


The Conformist
<author gender="male">Alberto Moravia
Alberto Moravia's classic psyhcological novel.


The Sun Also Rises
<author gender="male">Ernest Hemingway
The masterpiece that launched Hemingway's career.



php文件:
<div class="codetitle"><a style="CURSOR: pointer" data="73866" class="copybut" id="copybut73866" onclick="doCopy('code73866')"> 代码如下:
<div class="codebody" id="code73866">
<?PHP
$xml=simplexml_load_file("book.xml");echo "
";
var_dump($xml);
?>

输出结果:
<div class="codetitle"><a style="CURSOR: pointer" data="51840" class="copybut" id="copybut51840" onclick="doCopy('code51840')"> 代码如下:
<div class="codebody" id="code51840">
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."
}
}
}

原文链接:https://www.f2er.com/php/26388.html
SimpleXML函数加载解析XML文档

猜你在找的PHP相关文章