Forum Moderators: coopster

Message Too Old, No Replies

Safe to use experiment dom_xml functions?

         

rabbit_fufu

3:14 am on Mar 18, 2004 (gmt 0)

10+ Year Member



Hi guys, I'm hoping someone here can offer some advice...

I'm writing a content management system for a site and I'd really really like to take advantage of some of the new dom_xml functions to convert my db results to xml (... and from there to use a sablotron xsl transform to format the data etc etc...)

This would be soooo nice as I could then have complete seperation of formatting from my logic.

The Concern: When I check out some of these functions in the php manual it says that the function is "Experimental" and could change further down the road - USE AT YOUR OWN RISK.

Well, I would hate for my client's site to stop working at some point in the future. I guess I'm wondering if anyone knows how likely this scenario would be? Are these functions liable to change? Or is it an extremely remote chance? Can I feel confident using them in my projects or should I wait until they are no longer experimental?

Thanks in advance for your help!

-trav

coopster

6:33 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You'll have to ask the developers...

But seriously, as with anything that is still in experimental state, I would hesitate to use it in a production environment.

XMLMania

8:08 pm on Mar 18, 2004 (gmt 0)

10+ Year Member



to convert my db results to xml

This can be done easily without use the DOM functions, and it's faster.

use a sablotron xsl transform to format the data

Is this necessary? Most browsers now include a XSLT processor so you could do it client side.

rabbit_fufu

11:06 pm on Mar 18, 2004 (gmt 0)

10+ Year Member



Hi there,

thanks for the responses!

> This can be done easily without use the DOM
> functions, and it's faster.

Sorry, but I am not expert when it comes to xml conversion. Could you tell me a bit about the other methods that are available? Thanks!

As for sablotron, yeah, I'd prefer to use it. We're aiming for complete cross-compatability here so I'd rather not have to rely on the client-side to do the transform.

-trav

XMLMania

10:51 am on Mar 19, 2004 (gmt 0)

10+ Year Member



Examples of PHP + database -> XML


<?php
header("Content-type: text/xml");

$link = mysql_connect("localhost", "username", "password") or die("Cannot connect to database server.");

$db = mysql_list_dbs($link);

echo "<?xml version=\"1.0\"?>\n<?dbsml version=\"0.0.4-16-02-2004\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"dbsml.xsl\"?>\n";
echo "<dbsml xmlns:dbsml=\"http://xmlns.example.com/dbsml/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://xmlns.example.com/dbsml/schema.xsd\">";

while ($database = mysql_fetch_row($db)) {
echo "\n\t<database id=\"$database[0]\">";

$tables = mysql_list_tables($database[0]);

while ($table = mysql_fetch_row($tables)) {
echo "\n\t\t<table id=\"$table[0]\">";

$fields = mysql_list_fields($database[0], $table[0], $link);
$columns = mysql_num_fields($fields);

for ($i = 0; $i < $columns; $i++) {
$fieldName = mysql_field_name($fields, $i);
$fieldType = mysql_field_type($fields, $i);
$fieldLength = mysql_field_len($fields, $i);
$fieldFlags = mysql_field_flags($fields, $i);

echo "\n\t\t\t<field id=\"$fieldName\" type=\"$fieldType\" length=\"$fieldLength\" flags=\"$fieldFlags\" />";
}

echo "\n\t\t</table>\n";
}

echo "\t</database>\n";
}

mysql_free_result;
mysql_close;

echo "</dbsml>";
?>

Another example (to make a RSS feed):


<?php
header ("Content-type: text/xml");
mysql_connect ("localhost", "username", "password") or die ("Cannot connect to database server.");
mysql_select_db ("database") or die ("Cannot connect to database.");

echo ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
?>
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:hr="http://www.w3.org/2000/08/w3c-synd/#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/">
<channel rdf:about="">
<title>XRSS/RDF Feed</title>
<description></description>
<link></link>
</channel>
<?php
while ($row = mysql_fetch_array ($result)) {
$illegalChars = array(" ", "@", "'", ",", ":", ";", "?", "<", ">", '"', "(", ")", "*", "&", "^", "%", "$", "£", "!", "/", "#", "~", "{", "}", "[", "]", "+", "=", "--", "--");
$linkTitle = substr(stripslashes(str_replace($illegalChars, "-", $row['title'])), 0, 100);

echo ("\n\t<item rdf:about=\"news_article_$row[id]-$linkTitle.php\">\n\t\t <title>$row[title]</title>\n\t\t<description>$row[text]</description>\n\t\t <link>news_article_$row[id]-$linkTitle.php</link>\n\t\t<dc:date>$row[date]</dc:date>\n\t </item>\n");
}

mysql_free_result($result);
?></rdf:RDF>

Just edit these, name your own custom tags etc.

Hope this helps!

[edited by: jatar_k at 6:54 pm (utc) on Mar. 19, 2004]
[edit reason] fixed sidescroll [/edit]