怎么使用SimpleXML函数来加载和解析XML文档-创新互联

这篇文章将为大家详细讲解有关怎么使用SimpleXML函数来加载和解析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 "

";
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."
    }
  }
}


关于“怎么使用SimpleXML函数来加载和解析XML文档”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


文章名称:怎么使用SimpleXML函数来加载和解析XML文档-创新互联
标题URL:http://myzitong.com/article/cojghd.html