2011-06-27 41 views
0

我已經關注了 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);

請幫助:(

+0

好的,我編輯了相應的,改變了文件權限..仍然不工作:( – Pow

回答

2
$doc->save('http://myServer/config.xml'); 

無法寫入到http://的位置,http包裝不支持它。

改爲使用本地文件路徑。

+0

好吧,我試圖只使用文件名(因爲現在他們在同一目錄),但它仍然不工作。我保存回聲後,回聲不打印:( – Pow

+0

@你有錯誤報告打開嗎? –

+0

不,我沒有它:( – Pow