Hey guys, i have a question ..how can i use Magic Parser to parse a XML feed, like in your online demo. When it parses , everything is messed up and i was wondering how could i output it nicely. Look @ an example:
i have a xml feed with this part in it:
<performerid>Monserrat</performerid>
<category>Girls</category>
<subcategory>18_22</subcategory>
<age>19</age>
<sex>Female</sex>
i would like the output to be like this:
ID: Monserrat
Category: Girls
Subcategory 18_22
Age: 19
Sex: Female
im not VERY familiar with php but i know the basics, and if u could help me with this everything will be ok with my site :D. Tnx in advance
Hi,
The demo script on this website uses PHPs FOREACH construct to loop through the array that is passed to your record handler function. To display the results as in your example, you would do this:
<?php
function myRecordHandler($record)
{
// loop through the record
foreach($record as $key => $value)
{
print $key.": ".$value."<br />";
}
}
?>
Going one step further with the layout, the demo script on this website displays the results in a table, using TH cells for the field names and normal TD cells for the data. Here's how it works:
<?php
function myRecordHandler($record)
{
// start the table
print "<table border='1'>";
// loop through the record
foreach($record as $key => $value)
{
// print the row for each key value pair
print "<tr>";
print "<th>".$key."</th>";
print "<td>".$value."</td>";
print "</tr>";
}
// end the table
print "</table>";
}
?>
Hope this helps!
Cheers,
David.