iT邦幫忙

0

php DOMDocument

a.php

class modifyDocument extends DOMDocument{
    public  function setNodeValue($TagName,$obj){
        foreach ($obj as $Tag_Name=>$value){
            $Child_Node=$TagName->getElementsByTagName($Tag_Name)->item(0);
            $Child_Node->nodeValue = '';
            $Child_Node->appendChild($this->createCDATASection($value));
        }
    }
}

b.php

$dom=new DOMDocument();
$dom->load($File_path);
$Info_Node=(object)array('HospitalName'=>'','SheetName'=>'','FormSquence'=>'','PrinterDate'=>'');
$DocumentInfo=$dom->getElementsByTagName('Document');
$DocumentInfo_Child=$Document->item(0);
$dom->setNodeValue($DocumentInfo_Child,$Info_Node);
Fatal error: Uncaught Error: Call to undefined method DOMDocument::setNodeValue() 

請問各位大大在使用php 製作xml的時候因為想要新增方法,想請問為甚麼出現找不到我新增的方法,我應該加到php原生的檔案內嗎?

淺水員 iT邦大師 6 級 ‧ 2021-07-12 19:15:30 檢舉
b.php 你用
$dom=new DOMDocument();
這樣就用不到 a.php 的 modifyDocument 類別了
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答