simplexml_import_dom()函數(shù)用于從DOM節(jié)點(diǎn)獲取SimpleXMLElement對(duì)象。
simplexml_import_dom(node,classname);
從DOM節(jié)點(diǎn)返回SimpleXMLElement對(duì)象
成功時(shí),則返回SimpleXMLElement對(duì)象,失敗則返回false
序號(hào) | 參數(shù)和說(shuō)明 |
---|---|
1 | node 指定dom元素節(jié)點(diǎn) |
2 | classname 指定新對(duì)象的類 |
試試下面的實(shí)例,獲取 DOM 文檔節(jié)點(diǎn)并轉(zhuǎn)換為 SimpleXML 節(jié)點(diǎn):
<?php //獲取 DOM 文檔節(jié)點(diǎn)并轉(zhuǎn)換為 SimpleXML 節(jié)點(diǎn) $dom = new domDocument; $dom->loadXML("<car><local><title> Title1</title></local><local><title> Title2</title></local></car>"); $x = simplexml_import_dom($dom); echo $x->local[1]->title; ?>測(cè)試看看?/?
輸出結(jié)果
Title2