PHP5對象simplexml的詳細分析_PHP教程

來源:互聯網
上載者:User
simplexml_load_file(str file); 將一個xml文檔載入一個simplexml對象中,此方法返回一個控制代碼

simplexml_load_string(str string);將一段xml文檔載入一個simplexml對象中,此方法返回一個控制代碼

simplexml_import_dom(data) 該函數把一個dom節點轉為simplexml對象,其中data為實用的DOM節點

$simplexml->addAttribute(name,value) 給simplexml對象元素添加一個屬性,注意,是simplexml對象元素,不是simplexml物件控點。

$simplexml->addChlid(name,value)給指定的XML節點添加一個子節點

$simplexml->asXML() 從SimpleXMLElement對象中以一個字串的形式返回XML文檔,可以當作儲存xml文檔來來用

$simplexml->attributes() 返回由PHP5對象simplexml元素節點的屬性群組成的數組,

運行上面代碼會列印出以個數組,Array ( [@attributes] => Array ( [name] => cx,html [tt] => ddd ) )

可見,$simplexml->attributes()得到的是一個xml元素節點的所有屬性,不過被包含在一個[@attributes]數組中,所以要通過$xml = $xml['@attributes']來獲得

$simplexml->Children() 返回simplexml對象元素節點的孩子組成的數組

$simplexml->__construct() 建立一個新的XML文檔

$simplexml->getDocNamespaces() 該函數返回$simplexml對象定義的命名空間

$simplexml->getName() 返回$simplexml對象元素的名稱,即標籤名

$simplexml->getNamespaces() 返回$simplexml對象使用的命名空間

$simplexml->registerXpathNamespace() 該函數為下一次XPATH查詢建立命名空間語境

$simplexml->xpath() 使用xpath的文法來解析一個PHP5對象simplexml

執行個體代碼1

 
  1. xml version="1.0" encoding="gbk"?>
  2. <LeapsoulXML>
  3. <LeapsoulInfo>
  4. <name>Leapsoul-PHP網站開發name>
  5. <website>http://www.leapsoul.cnwebsite>
  6. <description>分享PHP網站開發與建設的樂趣,教你如何建立網站description>
  7. <bloger>Davidbloger>
  8. <date>2009-05-13date>
  9. <qq>QQ:154130270qq>
  10. LeapsoulInfo>
  11. <LeapsoulInfo>
  12. <name>Leapsoul-PHP網站開發name>
  13. <website>http://www.leapsoul.cnwebsite>
  14. <description>分享PHP網站開發與建設的樂趣,教你如何建立網站description>
  15. <bloger>Davidbloger>
  16. <date>2009-05-13date>
  17. <qq>QQ:154130270qq>
  18. LeapsoulInfo>
  19. LeapsoulXML>

我們可以結合上面的PHP5對象simplexml樣本,再加上自己的瞭解,應該能夠充分的認識這一新增的函數。


http://www.bkjia.com/PHPjc/446334.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446334.htmlTechArticlesimplexml_load_file(str file); 將一個xml文檔載入一個simplexml對象中,此方法返回一個控制代碼 simplexml_load_string(str string);將一段xml文檔載入一個simple...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.