I'm surprised that no one else already replied to this?!?! Anyhow, my answers are below.

Phil Dowson wrote:
Hi,

I am having a couple of difficulties with a script to parse XML. This may
well be because my 16 month kid was up all night, but I'm banging my head
against a wall right now.

OT: And this is why I'm still happily single. But my time will come.


The script quite easily extracts one of the entries listed under <DATA_2> but doesnt list the other. This is my first look into parsing XML, so I am not sure of the terminology :-). How can I have both entries in this XML file parsed to an array that I can use to build a table. (I just really need the array, I can take it from there).

So, make all of the xml children listed under LIST_2 become part of an array? I first have to ask if you're using PHP5 now (or will soon). The dev team has added a new simpleXML extension that handles this type of operation and it can be quite simple (imagine that!). An example straight from the site shows how to turn xml into an array:


<?php
// The file test.xml contains an XML document with a root element
// and at least an element /[root]/title.

if (file_exists('test.xml')) {
   $xml = simplexml_load_file('test.xml');

   var_dump($xml);
} else {
   exit('Failed to open test.xml.');
}
?>

This handy extension also allows you to use xpath.  For an overview see:
http://www.php.net/simplexml

If you're using PHP4 then I would suggest you try this PEAR package. It will create PHP objects from XML:
http://pear.php.net/package/XML_Tree


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to