Writing XML files using PHP

Writing XML

$memory = xmlwriter_open_memory();
xmlwriter_start_document($memory,'1.0','ISO-8859-1');

xmlwriter_start_element ($memory,'RSS'); // <rss>
xmlwriter_write_attribute( $memory, 'Version', '2.0');

xmlwriter_start_element($memory,'channel'); // <Channel>

xmlwriter_write_element ($memory,'title', 'My News Release');
xmlwriter_write_element ($memory,'link', 'http://www.tests.com/news.php');
xmlwriter_write_element ($memory,'Description', 'My Test News Release');
xmlwriter_write_element ($memory,'pubDate',date ('Y-m-d'));
while ($row=mysql_fetch_array($result))
{

xmlwriter_start_element ($memory, 'item');
xmlwriter_write_element ($memory,'title', $row['title']);
xmlwriter_write_element ($memory,'description', $row['description']);
xmlwriter_write_element ($memory,'link', $row['link']);
xmlwriter_write_element ($memory,'category', $row['category']);
xmlwriter_write_element ($memory,'pubDate', $row['pubDate']);
xmlwriter_write_element ($memory,'source', $row['source']);
xmlwriter_end_element ($memory); //</Item>

}

xmlwriter_end_element($memory); // </Channel>
xmlwriter_end_element($memory); // </RSS>

xmlwriter_end_dtd($memory);

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s