Hi everyone, this is my first post here and I hope you can help me out. I am trying to display only one entry from an XML document through PHP. May sound stupid, but its part of a CMS im building which cant use databases
The XML looks like this
<?xml version="1.0" encoding="iso-8859-1"?>
<data>
<entry id="1">
<description>description of entry one</description>
</entry>
<entry id="2">
<description>description of entry two</description>
</entry>
<entry id="3">
<description>description of entry three</description>
</entry>
</data>
I would like the output to show (if id=1, display 'description of entry one')
Here is my PHP, i know my echos are incorrect but I have no idea how to get it to show what I want. I don't think this should be an impossible task!
<?php
function startElement($parser_instance, $element_name, $attrs) {
echo "<br>$element_name";
}
function characterData($parser_instance, $xml_data) {
echo "<b>$xml_data</b>";
}
function endElement($parser_instance, $element_name) {
echo "/$element_name<br />";
}
$parser = xml_parser_create();
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "characterData");
$filehandler = fopen("cms.xml", "r");
while ($data = fread($filehandler, 4096)) {
xml_parse($parser, $data, feof($filehandler));
}
fclose($filehandler);
xml_parser_free($parser);
?>
Thanks for any help you can give