开发者

Write XML file with PHP on server

I have followed this example and created a php file to write into an xml file config.xml. But for some reason, when I'm trying to see what is written in my xml file, I don't see anything. Here's my code -

    $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');

I have checked it with echos and there is no syntax error. Can anyone please tell me what's I'm doing wrong here?

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

I'm getting error - Fatal error: Call to a member function appendChild() on a non-object in /var/www/html/PasswARGUI1/myWriteXML.php on line 103

It is indicating this line - $doc->documentElement->appendChild($porpoiseconfig开发者_如何学Curation);

Please Help :(


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

you can't write to a http:// location, the http wrapper doesn't support it.

Use a local file path instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜