I’m just starting to learn how to use PHP, mySQL and XML with Flash. My question comes out of the article here at Kirupa. (I’ve got a great start, thanks jubba!).
Can the mySQL data output be generated as attributes in the tag instead of nested between the tags? Lee Brimelow (in one of his tutorials) says he thinks it’s easier to work with data in an attribute instead of nested between the tags.
so if my xml output looks like this:
<?xml version="1.0"?>
<entries>
<entry>
<title>First Title</title>
<article>This is the first entry.</article>
</entry>
</entries>
from this:
$xml_output = "<?xml version=\"1.0\"?>
";
$xml_output .= "<entries>
";
for($x = 0 ; $x < mysql_num_rows($result) ; $x++){
$row = mysql_fetch_assoc($result);
$xml_output .= " <entry>
";
$xml_output .= " <title>" . $row['title'] . "</title>
";
// Escaping illegal characters
$row['text'] = str_replace("&", "&", $row['article']);
$row['text'] = str_replace("<", "<", $row['article']);
$row['text'] = str_replace(">", ">", $row['article']);
$row['text'] = str_replace("\"", """, $row['article']);
$xml_output .= " <article>" . $row['article'] . "</article>
";
$xml_output .= " </entry>
";
}
$xml_output .= "</entries>";
echo $xml_output;
Can i use PHP to output mySQL data as XML to look like this?:
<?xml version="1.0"?>
<entries>
<entry title="First Title" article="This is the first entry." />
</entries>
Any push in the right direction would be appreciated. Thanks!