hai experts,regarding php-xml

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulragav
    New Member
    • Mar 2008
    • 4

    hai experts,regarding php-xml

    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($ro ot);

    $filename = $dom -> createElement(" filename");
    $root -> appendchild($fi lename);
    $text = $dom->createTextNode ($obj1->filename);
    $filename -> appendchild($te xt);


    $filepath = $dom->createElement( "filepath") ;
    $root -> appendchild($fi lepath);
    $text = $dom -> createTextNode( $obj1->filepath);
    $filepath -> appendchild($te xt);
    echo $dom -> saveXML();

    ?>

    the simple.php file (class) is

    <?php

    class request
    {
    public function request()
    {

    $this->filename="fibo nacci.php";
    $this->filepath="15.1 56.12.244/dirname";
    }

    }
    ?>

    And output is as follows

    <?xml version="1.0" ?>
    - <request>
    <filename>fibon acci.php</filename>
    <filepath>15.15 6.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..
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    It would help a lot if you respected the people you are looking to get help from and put your code within the appropriate code tags! See the Posting Guidelines on that.

    moderator

    Comment

    • rahulragav
      New Member
      • Mar 2008
      • 4

      #3
      Originally posted by ronverdonk
      It would help a lot if you respected the people you are looking to get help from and put your code within the appropriate code tags! See the Posting Guidelines on that.

      moderator
      Dear sir,
      After reading your reply to my post,i realise my mistake. I always have great respect and regards to everyone.Since i was posting for the first time,i was confused as to how formal it should be.. And i believe it's my improper use of certain words that created a feel of some disrespect..But it was not intentional.
      Once again i plead sorry and assure to correct myself in future.
      regards,
      rahul.

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        I shouldn't have to do this for you... but...

        [PHP]
        <?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($ro ot);

        $filename = $dom -> createElement(" filename");
        $root -> appendchild($fi lename);
        $text = $dom->createTextNode ($obj1->filename);
        $filename -> appendchild($te xt);


        $filepath = $dom->createElement( "filepath") ;
        $root -> appendchild($fi lepath);
        $text = $dom -> createTextNode( $obj1->filepath);
        $filepath -> appendchild($te xt);
        echo $dom -> saveXML();

        ?>[/PHP]

        the simple.php file (class) is
        [PHP]
        <?php

        class request
        {
        public function request()
        {
        $this->filename="fibo nacci.php";
        $this->filepath="15.1 56.12.244/dirname";
        }
        }
        ?>[/PHP]

        Comment

        • dlite922
          Recognized Expert Top Contributor
          • Dec 2007
          • 1586

          #5
          Originally posted by rahulragav

          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 .
          First: don't need to use two classes it looks like, create one class and create an associative array as the data member. to traverse and output the XML, use foreach().

          Originally posted by rahulragav
          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 have no idea what you mean here by storing them against any variable.

          please elaborate.

          Comment

          • rahulragav
            New Member
            • Mar 2008
            • 4

            #6
            Originally posted by dlite922
            First: don't need to use two classes it looks like, create one class and create an associative array as the data member. to traverse and output the XML, use foreach().



            I have no idea what you mean here by storing them against any variable.

            please elaborate.
            Dear Sir,
            Thank you very much, for reading and replying to my problem.

            "storing them against any variable" - the actual task is to access the xml data.

            If i m using simple xml, the coding just extracts the xml data and display it in the browser. But ,my project involves creation of an interface that provide this xml data input to an adaptor.
            So along with the xml data extraction, we have to assign them to certain variables.Then the adaptor will be able to use this data by calling those variables (arguments of the function call)
            Very sorry sir,for i am not able to show the adaptor code here as it is being handled by a different team.
            regards,
            rahul.

            Comment

            • rahulragav
              New Member
              • Mar 2008
              • 4

              #7
              Originally posted by dlite922
              I shouldn't have to do this for you... but...

              [PHP]
              <?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($ro ot);

              $filename = $dom -> createElement(" filename");
              $root -> appendchild($fi lename);
              $text = $dom->createTextNode ($obj1->filename);
              $filename -> appendchild($te xt);


              $filepath = $dom->createElement( "filepath") ;
              $root -> appendchild($fi lepath);
              $text = $dom -> createTextNode( $obj1->filepath);
              $filepath -> appendchild($te xt);
              echo $dom -> saveXML();

              ?>[/PHP]

              the simple.php file (class) is
              [PHP]
              <?php

              class request
              {
              public function request()
              {
              $this->filename="fibo nacci.php";
              $this->filepath="15.1 56.12.244/dirname";
              }
              }
              ?>[/PHP]


              Thanks a lot sir,for viewing and correcting my post.
              I assure you that in future i ll try to learn more and improve my ways of posting in forums.

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                Originally posted by rahulragav
                Thanks a lot sir,for viewing and correcting my post.
                I assure you that in future i ll try to learn more and improve my ways of posting in forums.
                Okay, that is allright. See you again.

                Ronald

                Comment

                Working...