2011-06-27 23 views
0

私は this exampleに続き、xmlファイル​​3210に書き込むphpファイルを作成しました。しかし何らかの理由で、私が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'); 

私はエコーでそれをチェックし、構文エラーはありません。誰でも私にここで間違っていることを教えてもらえますか?

EDIT ::::::::::::

私はエラーを取得しています - 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

OK、私はファイル名を使用しようとしています(今のところ同じディレクトリにあるので)。 – Pow

+0

@Powエラー報告がオンになっていますか? –

+0

いいえ私はそれを持っていません:( – Pow

関連する問題