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

WBOY
Libérer: 2016-07-21 15:08:13
original
972 Les gens l'ont consulté

大量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>
Copier après la connexion

输出结果:
复制代码 代码如下:

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/327494.htmlTechArticle大量SmipleXML函数可用来加载和解析大量XML文档。 -------------------------------------------------------------------------------- 1. simpleXML_load_file() 函数来加载...
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!