Jump to content

php-xml help,plzzz


rahulragav

Recommended Posts

Hi php-xml masters there ,warm greetings from this budding php guy..I'm new to this..and now caught up with a problem..

 

THE FOLLOWING is my code to extract data from a php class "simple.php"

My task is to generate  xml documents ,that i'm  able to do now.

 

 

<?php

 

class compile1

{

  function compile1()

  {

      include "simple.php";

      $obj = new request;

      $this -> filename = $obj -> filename;

      $this -> filepath = $obj -> filepath;

        }

}

      $obj1=new compile1;

      $dom=new DOMDocument("1.0");

      $dom->formatOutput = true;

      header("Content-Type:text/plain");

 

      $root = $dom->createElement("request");

      $dom -> appendchild($root);

 

      $filename = $dom -> createElement("filename");

      $root -> appendchild($filename);

      $text = $dom->createTextNode($obj1->filename);

      $filename -> appendchild($text);

 

 

      $filepath = $dom->createElement("filepath");

      $root -> appendchild($filepath);

      $text = $dom -> createTextNode($obj1->filepath);

      $filepath -> appendchild($text);

        echo $dom -> saveXML();

 

?>

 

the simple.php file (class) is 

 

<?php

 

      class request

        {

                public function request()

                {

 

                  $this->filename="fibonacci.php";

                  $this->filepath="15.156.12.244/dirname";

                }

 

        }

?>

 

And output is as follows

 

  <?xml version="1.0" ?>

- <request>

  <filename>fibonacci.php</filename>

  <filepath>15.156.12.244/dirname</filepath>

    </request>

 

Now here are my problems..

 

1.The tags in this XML output are hard coded.I want to make it dynamic i.e ,tags should be dynamically generated based on the class provided .

 

2.I ve to store this output in a file  (.xml) and i have to retrieve each value of node by storing them against any variables ,so that other functions can access this xml elements  using those variable names..

   

  I tried diffrent ways and still trying.

        Any masters and experts reading this , please help.

regards

rahul..

 

Link to comment
https://forums.phpfreaks.com/topic/94877-php-xml-helpplzzz/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.