我已經關注了 this example並創建了一個php文件來寫入一個xml文件3210。但出於某種原因,當我試圖查看我的xml文件中寫入的內容時,我什麼都看不到。這是我的代碼 -在服務器上用PHP寫入XML文件
$doc=new DOMDocument("1.0");
//load the file
$doc->load('localpath/config.xml');
echo 'Start writing the xml file1';
//create chapter-element
$porpoiseconfiguration=$doc->createElement('porpoise-configuration');
//create title-element
echo 'Start writing the xml file2';
$developerid=$doc->createElement('developer-id');
//insert text to the title
$developerid->appendChild($doc->createTextNode('00'));
$developerkey=$doc->createElement('developer-key');
//insert text to the title
$developerkey->appendChild($doc->createTextNode('00'));
echo 'In the 1st middle writing3';
$connectors=$doc->createElement('connectors');
$connector=$doc->createElement('connector');
$name1=$doc->createElement('name');
$name1->appendChild($doc->createTextNode('Silverspring'));
$file=$doc->createElement('file');
$file->appendChild($doc->createTextNode('silverspringpoiconnector.class.php'));
echo 'In the 1st middle writing4';
$connector->appendChild($name1);
$connector->appendChild($file);
$connectors->appendChild($connector);
echo 'In the 1st middle writing5';
$layers=$doc->createElement('layers');
$layer=$doc->createElement('layer');
$name2=$doc->createElement('name');
$name2->appendChild($doc->createTextNode('gamename'));
$source=$doc->createElement('source');
$dsn=$doc->createElement('dsn');
$dsn->appendChild($doc->createTextNode("mysql:host=myhost;dbname='$dbname'"));
$username=$doc->createElement('username');
$username->appendChild($doc->createTextNode('myusername'));
$password=$doc->createElement('password');
$password->appendChild($doc->createTextNode('mypass'));
$source->appendChild($dsn);
$source->appendChild($username);
$source->appendChild($password);
$layer->appendChild($source);
$layer->appendChild($name2);
$connector2=$doc->createElement('connector');
$connector2->appendChild($doc->createTextNode('SilverspringPOIConnector'));
echo 'In the 1st middle writing6';
$layers->appendChild($layer);
$layers->appendChild($connector2);
echo 'In the 1st middle writing7';
$porpoiseconfiguration->appendChild($developerid);
$porpoiseconfiguration->appendChild($developerkey);
$porpoiseconfiguration->appendChild($connector);
$porpoiseconfiguration->appendChild($layers);
echo 'In the 1st middle writing8';
$doc->documentElement->appendChild($porpoiseconfiguration);
//$doc->documentElement->appendChild($chapter);
echo 'done writing';
echo $doc->saveXML();
$doc->save('localpath/config.xml');
我檢查了它與回聲,並沒有語法錯誤。任何人都可以告訴我我在這裏做錯了什麼?
編輯::::::::::::
我收到提示 - Fatal error: Call to a member function appendChild() on a non-object in /var/www/html/PasswARGUI1/myWriteXML.php on line 103
它表明這條線 - $doc->documentElement->appendChild($porpoiseconfiguration);
請幫助:(
好的,我編輯了相應的,改變了文件權限..仍然不工作:( – Pow