Good morning,
I am trying to extract some data from a XML file. I have the basics working, but I am having problems getting it to pull out the software ID.
Using a simple XML file as an example, I cannot get my php to pull out the unique software id
<?xml version="1.0" encoding="UTF-8"?>
products count="5" rendertime="1.620">
<software id="5667391" added="2010-05-27" updated="2010-05-27">
<title><![CDATA[World Cup South Africa 2010 Scoreboard 1.0.1]]></title>
<name><![CDATA[World Cup South Africa 2010 Scoreboard]]></name>
<short_description><![CDATA[This program automates all the scores, schedules and rankings of all matches at the FIFA 2010 Soccer World Cup in South Africa.]]></short_description>
</software>
</products>
My relevant PHP section is as follows:
$xmlReader = new XMLReader ();
$filename="/files/testfile.xml";
$xmlReader ->open($filename);
while ($xmlReader->read())
{
switch ($xmlReader->name)
{
case 'software':
$dom = new DOMDocument();
$domNode = $xmlReader->expand();
$element = $dom->appendChild($domNode);
$domString = utf8_encode($dom->saveXML($element));
$product = new SimpleXMLElement($domString);
//read in data
$name = $product->name;
$description = $product->short_description;
$software_id = $product->id;
echo $software_id . "software ID <br />";
echo $name . "name <br />";
echo $description . "description <br />";
It pulls out the name and description succesfully, but not the software id.
Can anyone suggest what I am doing wrong please? I have also tried changing the software_id line to the following, but that also returns a blank
$software_id = $product->'software id';
I've about reached my technical limits, googling on SimpleXMLElement($domString); hasn't helped at all 🙁
Thanks in advance,
Greg