Has anyoane done this?I'm new with php and in need for help.
Please help.


First, you will have provide us with the tags for your xml files. What I meant by tags is your own mark up based on your needs or how do you want the xml file structured.

something like this,

<?xml version="1.0"?>
<title>my title</title>
<description>my description</description>

Second, you will have to provide us with your sample html document, so that we are able to see if it can be parsed using PHP, and then ultimately write the parsed data in xml format as file or directly to the browser.

example of possible HTML doc..

<h1> Title </h1>
<p> My description</p>

Veedeoo the xml structure should be like the one you proposed but with a root node named company.
I've managed to get an array from the html.My problems is now etracting the data that I need to put in the xml file.My problem now is that for every item in the array for example:

` [1]=>
  string(371) "<tr align="left">
                    <td width="345" bgcolor="#fcf8f5" ><font size="2" color="#0B0B0B"
                        face="Times New Roman">**Adress:**</font></td>
                    <td align="center" width="330" bgcolor="#fcf8f5" ><font size="2"
                        face="Times New Roman">
                        **1042 Forest,Budapest**          

the data ("Adress") should be my items title and ("1042 Forest,Budapest") should be items description,and I now I need to extract that data somehow...

Example of XML structure,this is how I want to make it look:

<address>Str. Tulcea 24 Cluj</address>
<name>B It Company Srl</name>
<registration_id>J12 /3408 /2005</registration_id>
<created_at type="datetime">2013-01-29T12:18:34+00:00</created_at>
<updated_at type="datetime">2013-01-29T12:18:34+00:00</updated_at>
<consecutive_update_fails type="integer"/>

so..is there any way to get the data that I need from that array??


Sorry for late response... If will be difficult to parse html by converting them into array like that and then re-parse for the xml writter script.

What we need to do is use a dom html parser..download this file from sourceforge and test it with simple html first..,

follow this instruction here..

for example, if we have a simple html document like this

 <title>this is going to be parsed</title>
 <td>address 1</td>
 <td>address 2</td>
 <td>address 3</td>

The sample PHP for the parser can be like this..

$html = file_get_html('htmllocation');

function parse_this($html){
$td_data = array();
foreach($html->find('tr') as $row){
   foreach($row->find('td') as $item){
    $td_data[] = $item;

## address 1 to 3 are in this array

return $$td_data;


## test it
print_r (parse_this($html));

Let me know if you successfully print out the array as shown in my example... Once you got it working, it will be so easy to generate an xml file..

you could use the header('Content-type: text/xml'); then try to print a xml tags
like the example below as it get data from the table the data will be displayed as xml

              $stmt = "select * from table";
              $query = mysql_query($stmt);

              $data = array();
                    $data[] = array($_GET['query'] => $row);
                echo generate_response($data);

function generate_response($data){
    $retval = header('Content-type: text/xml');
    $retval .='<data>';
        foreach($data as $val => $value){
                foreach($value as $key => $cont){
                        $retval .= '<'.$key.'>';
                        foreach($cont as $tag => $htm){
                        $retval .='</'.$key.'>';
    $retval .= '</data>';
    return $retval;

Thank you all for support.I've managed to make it work.