Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xml dom to read a file

Reply
Thread Tools

xml dom to read a file

 
 
mr_burns
Guest
Posts: n/a
 
      08-06-2004
hi,

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. the reason i
have asked for xml dom is because i have checked that the server has
this enabled (i have learned that much). otherwise, are their any
short tutorials on this? cheers

burnsy
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      08-06-2004


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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getNextSibling() never ends? DOM XML nodes (org.w3c.dom) Alan Java 6 10-13-2008 05:48 PM
Replacing _xmlplus.dom.minidom with xml.dom.minidom aine_canby@yahoo.com Python 3 08-03-2007 03:50 PM
Attributes in XML file conflict problem? How to read them from DOM =?Utf-8?B?ZGF2aWQ=?= ASP .Net 1 03-08-2007 10:08 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Convert a XML DOM Object to a HTML DOM Object manjunath.d@gmail.com XML 0 09-20-2005 08:16 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57