I am trying to read a large XML file and add it to a database. Here is a very small example of the XML: <?xml version="1.0" encoding="UTF-8"?> <shows> <show id="33041"> <title>The Sound of Music</title> <category>Musicals</category> <price currency="GBP"> <min_price>12</min_price> <max_price>42</max_price> </price> </show> </shows> PHP: The problem is that I do not know how to refer to the id value in <show id="33041"> Here is a snippet of code I am using: $xml = new XMLReader(); $xml->open(Test.xml); while ($xml->read()) { switch ($xml->name) { case "event": $xml->read(); $conf["event"] = $xml->value; $xml->read(); break; } } PHP: So how on earth do I get the id bit???? Thanks for any help.
$arr = array(); $xml = simplexml_load_file('Test.xml'); foreach($xml->show as $show) { $show_attributes = $show->attributes(); $arr[] = $show_attributes['id']; } print_r($arr); Code (markup): $arr is an array populated with the id's of each <show> within <shows>
Thanks very much. That helps for small files but some of the XML I have are 500mb! Thanks your code will help me.