Hi everyone i have an xml which display data from the database i have it on a while loop but i am unable to style i don’t know why is not wrokin can someone help me out please.
xml file
<?php
// PHP file that renders perfect Dynamic XML for MySQL Database result sets
// Script written by Adam Khoury @ www.developphp.com - April 05, 2010
// View the video that is tied to this script for maximum understanding
// -------------------------------------------------------------------
header("Content-Type: text/xml"); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
// Connect to your MySQL database whatever way you like to here
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("admin") or die ("no database");
// Execute the Query on the database to select items(20 in this example)
$sql = mysql_query("SELECT * FROM news ORDER BY news_date DESC LIMIT 0, 20");
while($row = mysql_fetch_array($sql)){
// Set DB variables into local variables for easier use
$news_id = $row["news_id"];
$subject = $row["subject"];
$news_date = strftime("%b %d, %Y", strtotime($row["news_date"]));
$news_artical = $row["news_artical"];
// Start filling the $xmlBody variable with looping content here inside the while loop
// It will loop through 20 items from the database and render into XML format
$xmlBody .= '
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>' . $news_id . '</title>
<artist>' . $subject . '</artist>
<country>' . $news_date . '</country>
<company>' . $description . '</company>
</cd>
</catalog>';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody; // output the gallery data as XML file for flash
?>
The first thing I wanted to do was test the script’s output. But I was too lazy to make a database for it so I commented out the db lines and used an array.
You will need to use XSLTProcessor to apply the transformation and actually return the resulting XML. Otherwise, the transformation may be applied but the XML output will be the XML without the transformation. The transformation will just take affect in the browser, but not the source. That is part of the problem, there may be others.
Hi thanks for your replies but unfotunaly still didnt solve the problems i am trying to research more about (XSLTProcessor) i would still apreciate any further help from anyone
no i havent used the array because the data has to come from the database so and it does produce the xml structure but it just doesnt pick the stylesheet
Hi guys i’m back was on holiday. and still having problems with xml to be styled
xml doesnt pick the stylesheet can someone help me oout please you can check out how the data looks on my site here
this the code
<?php
// PHP file that renders perfect Dynamic XML for MySQL Database result sets
// Script written by Adam Khoury @ www.developphp.com - April 05, 2010
// View the video that is tied to this script for maximum understanding
// -------------------------------------------------------------------
header("Content-Type: text/xml"); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
// Connect to your MySQL database whatever way you like to here
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("admin") or die ("no database");
// Execute the Query on the database to select items(20 in this example)
$sql = mysql_query("SELECT * FROM news ORDER BY news_date DESC LIMIT 0, 20");
while($row = mysql_fetch_array($sql)){
// Set DB variables into local variables for easier use
$news_id = $row["news_id"];
$subject = $row["subject"];
$news_date = strftime("%b %d, %Y", strtotime($row["news_date"]));
$news_artical = $row["news_artical"];
// Start filling the $xmlBody variable with looping content here inside the while loop
// It will loop through 20 items from the database and render into XML format
$xmlBody .= '
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>' . $news_id . '</title>
<artist>' . $subject . '</artist>
<country>' . $news_date . '</country>
<company>' . $description . '</company>
</cd>
</catalog>';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody; // output the gallery data as XML file for flash
?>
header("Content-Type: text/xml "); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
$xmlBody .= '
<?xml version="1.0" encoding="ISO-8859-1"?><XML>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>' . $news_id . '</title>
<title>' . $subject . '</title>
<title>' . $news_date . '</title>
<title>' . $news_artical . '</title>
</cd>
</catalog>
';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody; // output the gallery data as XML file for flash
?>
gave the above error
XML Parsing Error: XML or text declaration not at start of entity
Location: http://localhost/old_xampp_work/c3232585/rssdatabase.php
Line Number 5, Column 1:<?xml version=“1.0” encoding=“ISO-8859-1”?><XML>
^
i’m not sure if its cz i am missing an php open or or close tagthis how evrything looking now
<?php
header("Content-Type: text/xml"); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?> ';
$xmlBody .= "<catalog> ";
$xmlBody .= "<?xml-stylesheet type="text/xsl" href="books06.xsl"?> ";
?>
$xmlBody .= "
<?php // Connect to your MySQL database whatever way you like to here
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("admin") or die ("no database");
// Execute the Query on the database to select items(20 in this example)
$sql = mysql_query("SELECT * FROM news ORDER BY news_date DESC LIMIT 0, 20");
while($row = mysql_fetch_array($sql)){
// Set DB variables into local variables for easier use
$news_id = $row["news_id"];
$subject = $row["subject"];
$news_date = strftime("%b %d, %Y", strtotime($row["news_date"]));
$news_artical = $row["news_artical"];
// Start filling the $xmlBody variable with looping content here inside the while loop
// It will loop through 20 items from the database and render into XML format
$xmlBody .= '
<cd>
<title> ' . $news_id . '</title>
<artist> ' . $subject . '</artist>
<country> ' . $news_date . '</country>
<company> ' . $description . '</company>
</cd> ';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</catalog> ";
echo $xmlBody; // output the gallery data as XML file for flash
?>