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
- xml version="1.0" encoding="gbk"?>
- <LeapsoulXML>
- <LeapsoulInfo>
- <name>Leapsoul-PHP網站開發name>
- <website>http://www.leapsoul.cnwebsite>
- <description>分享PHP網站開發與建設的樂趣,教你如何建立網站description>
- <bloger>Davidbloger>
- <date>2009-05-13date>
- <qq>QQ:154130270qq>
- LeapsoulInfo>
-
- <LeapsoulInfo>
- <name>Leapsoul-PHP網站開發name>
- <website>http://www.leapsoul.cnwebsite>
- <description>分享PHP網站開發與建設的樂趣,教你如何建立網站description>
- <bloger>Davidbloger>
- <date>2009-05-13date>
- <qq>QQ:154130270qq>
- LeapsoulInfo>
- 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...