XML to PHP for MySQL Entry

Hi, I have an external XML File which I want to parse into PHP so that I can enter the information from the XML file into a MySQL database.

There are around 100 entries on the XML file but the basic layout is:

 
<root>
&#8722;
<property>
<id>13</id>
<date>2008-08-19 14:57:43</date>
<ref>MC-113</ref>
<sale_rent>sale</sale_rent>
<price>35000</price>
<type>Ruin</type>
<town>LUBRIN</town>
<village>Pozo Al Saez</village>
<province>Almeria</province>
<beds>0</beds>
<baths>0</baths>
<garden>Yes</garden>
<pool>Private</pool>
&#8722;
<desc>
This is a detached ruin with panaramic view and abit of land. It is suitated in a small Spaninsh hamlet with a stunning mountain and goats views, where noboby can find you. How ever it is very easy road access. It has electric and water and it is within 10 &shy;15 mins to Arboleas, Lubrin and Albanchez.  Ideal for people that have had enough fof life and are seeking peace and quite.
The plot size is 123m2 and the build size is 65m2.
There is room to build a pool.
</desc>
&#8722;
<images>
&#8722;
<image id="1">
&#8722;
<url>
http://www.website.com/images/properties//Imagen_292.jpg
</url>
<primary>1</primary>
<title>Fresh Water spring</title>
</image>
&#8722;
<image id="2">
&#8722;
<url>
http://www.website.com/images/properties//P9150005.jpg
</url>
<title>Ruin</title>
</image>
&#8722;
<image id="3">
&#8722;
<url>
http://www.website.com/images/properties//P9150008.jpg
</url>
<title/>
</image>
&#8722;
<image id="4">
&#8722;
<url>
http://www.website.com/images/properties/P9150006.jpg
</url>
<title/>
</image>
</images>
</property>
</root>

The thing is that not all of the entries have the same properties, ie some don’t have a pool entry, some have 2 images, not 4. When trying to parse this with xPath.class if an element is missing, it will pick up the element from the next entry and put it in the previous entries place, making the entry into the database completely wrong unless all fields are complete, which they wont be.

Here is the PHP code I’ve got so far:

<?
require("XPath.class.php");
 
$xPath = new XPath();
$xPath->importFromFile(http://www.website.com/xml.xml);
$ext_id = $xPath->match("//id");
$date = $xPath->match("//date");
$ref = $xPath->match("//ref");
$sale_rent = $xPath->match("//sale_rent");
$price = $xPath->match("//price");
$type = $xPath->match("//type");
$town = $xPath->match("//town");
$village = $xPath->match("//village");
$province = $xPath->match("//province");
$beds = $xPath->match("//beds");
$baths = $xPath->match("//baths");
$pool = $xPath->match("//pool");
$garden = $xPath->match("//garden");
$furnished = $xPath->match("//furnished");
$availability = $xPath->match("//availability");
$date_available = $xPath->match("//date_available");
$desc = $xPath->match("//desc");
$image_1 = $xPath->match("//image[@id=1]/url");
$image_1_title = $xPath->match("//image[@id=1]/title");
$image_2 = $xPath->match("//image[@id=2]/url");
$image_2_title = $xPath->match("//image[@id=2]/title");
$image_3 = $xPath->match("//image[@id=3]/url");
$image_3_title = $xPath->match("//image[@id=3]/title");
$image_4 = $xPath->match("//image[@id=4]/url");
$image_4_title = $xPath->match("//image[@id=4]/title");
$image_5 = $xPath->match("//image[@id=5]/url");
$image_5_title = $xPath->match("//image[@id=5]/title");
$countResult = count($ext_id); 
for ($i = 0; $i < $countResult; $i++)
{
 
 echo "<strong>ID: </strong>". $xPath->getData($ext_id[$i])."<br>";
 echo "<strong>Date Amended: </strong>". $xPath->getData($date[$i])."<br>";
 echo "<strong>Ref: </strong>". $xPath->getData($ref[$i])."<br>";
 echo "<strong>Sale or Rent: </strong>". $xPath->getData($sale_rent[$i])."<br>";
 echo "<strong>Price: </strong>". $xPath->getData($price[$i])."<br>";
 echo "<strong>Property Type: </strong>". $xPath->getData($type[$i])."<br>";
 echo "<strong>Location: </strong>". $xPath->getData($town[$i])."<br>";
 echo "<strong>Village: </strong>". $xPath->getData($village[$i])."<br>";
 echo "<strong>Province: </strong>". $xPath->getData($province[$i])."<br>";
 echo "<strong>Bedrooms: </strong>". $xPath->getData($beds[$i])."<br>";
 echo "<strong>Bathrooms: </strong>". $xPath->getData($baths[$i])."<br>";
 echo "<strong>Pool: </strong>". $xPath->getData($pool[$i])."<br>";
 echo "<strong>Garden: </strong>". $xPath->getData($garden[$i])."<br>";
 echo "<strong>Furnished: </strong>". $xPath->getData($furnished[$i])."<br>";
 echo "<strong>Availability: </strong>". $xPath->getData($availability[$i])."<br>";
 echo "<strong>date Available: </strong>". $xPath->getData($date_available[$i])."<br>";
 echo "<strong>Description: </strong>". $xPath->getData($desc[$i])."<br>";
 echo "<strong>Image 1: </strong>". $xPath->getData($image_1[$i])."<br>";
 echo "<strong>Image 1 Title: </strong>". $xPath->getData($image_1_title[$i])."<br>";
 echo "<strong>Image 2: </strong>". $xPath->getData($image_2[$i])."<br>";
 echo "<strong>Image 2 Title: </strong>". $xPath->getData($image_2_title[$i])."<br>";
 echo "<strong>Image 3: </strong>". $xPath->getData($image_3[$i])."<br>";
 echo "<strong>Image 3 Title: </strong>". $xPath->getData($image_3_title[$i])."<br>";
 echo "<strong>Image 4: </strong>". $xPath->getData($image_4[$i])."<br>";
 echo "<strong>Image 4 Title: </strong>". $xPath->getData($image_4_title[$i])."<br>";
 echo "<strong>Image 5: </strong>". $xPath->getData($image_5[$i])."<br>";
 echo "<strong>Image 5 Title: </strong>". $xPath->getData($image_5_title[$i])."<br>";
 
 $xPath->reset();
}
 
?>

Can anyone see how to get the elements of each entry while leaving them if they are empty and moving onto the next entry?