mr_burns wrote:
> i am currently tryin to learn enough xml dom to read a simple xml file
> and output the contents using php. at the moment i am reading a book
> (professional php4 xml) but i am running out of time as i kinda need
> to get it up asap. below is how the xml file will be presented:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <products>
> <item name="gold">
> <price>15.00</price>
> </item>
> <item name="silver">
> <price>12.50</price>
> </item>
> <item name="bronze">
> <price>10.00</price>
> </item>
> </products>
>
> if its not too much code, could someone please tell me how i would do
> this? i only need to read the file and print the output.
Here is an example:
<?php
$xml_document = domxml_open_file('test2004080602.xml');
if ($xml_document) {
$items = $xml_document->get_elements_by_tagname('item');
$itemCount = count($items);
echo "<ul>\r\n";
for ($i = 0; $i < $itemCount; $i++) {
$item = $items[$i];
$prices = $item->get_elements_by_tagname('price');
$price = $prices[0];
if ($price) {
$price = $price->first_child();
echo '<li>' . $item->get_attribute('name') . ' costs ' .
$price->node_value() .
"</li>\r\n";
}
}
echo "</ul>\r\n";
}
?>
--
Martin Honnen
http://JavaScript.FAQTs.com/