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..
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..
Comment