源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-12-09 22:41 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:探讨如何使用SimpleXML函数来加载和解析XML文档
大量SmipleXML函数可用来加载和解析大量XML文档。 -------------------------------------------------------------------------------- 1.[b]simpleXML_load_file()[/b]函数来加载指定的XML文件到对象。如果加载文件时遇到问题,则返回FLASE。例: book.xml文件:
[u]复制代码[/u] 代码如下:
<?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文件:
[u]复制代码[/u] 代码如下:
<?php $xml=simplexml_load_file("book.xml");echo "<pre>"; var_dump($xml); ?>
输出结果:
[u]复制代码[/u] 代码如下:
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."     }   } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部