Hello -
First time poster and pretty new to PHP. I have tried to research this before posting but I couldn't find any tutorials with this exact scenario.
I am trying to create a PHP file that reads an XML file with the following layout:
<Root>
-
<Vehicle="Red">
<Trip>1108</Trip>
<Platform>123RFIES</Platform>
<InformationType>Slow</InformationType>
</Red>
-
<Vehicle="Red">
<Trip>1108</Trip>
<Platform>123RSHAS</Platform>
<InformationType>Fast</InformationType>
</Red>
I am using the following PHP:
<?php
$file = "Vehicle.xml";
function contents($parser, $data){
echo $data;
}
function startTag($parser, $data){
echo "<b>";
}
function endTag($parser, $data){
echo "</b><br />";
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($file, "r");
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
?>
Using this code I can read the entire XML and display it on the webpage. What I am trying to do is filter it so it only displays when InformationType = Fast and only display the Trip and the InformationType. Where do I add this filter logic?
Thank you in advance!
-Adam