Jump to content

Converting XML


adamjblakey

Recommended Posts

Hi,

 

I seem to be having a problems with this one below that i hope someone can help with.

 

I am trying to create a form that will convert an XML file into SQL. It all works fine apart from one problem below.

 

This is the code:

 

$xml = simplexml_load_file('../database/PropertyInvestment.xml');

foreach ($xml->xpath('/Investments/Investment') AS $property)
{
    $property = array_map('trim', (array)$property);
    extract($property);

    mysql_query("INSERT INTO investments
(property_id, risk, location1, location2, type1, type2, type3)
        VALUES
            ('" . $Property_ID . "', '" . $Risk . "', '" . $property->Locations->Location[0] . "', '" . $property->Locations->Location[1] . "', '" . $property->Types->Type[0] . "', '" . $property->Types->Type[1] . "', '" . $property->Types->Type[2] . "')
    ") OR die(mysql_error());
}

 

It won't add the values for $property->Types->Type[0], $property->Types->Type[1] etc and just adds a blank entry.

 

Here is an example of the XML

 

<?xml version="1.0" encoding="ISO-8859-2" ?><Investments><Investment><Property_ID>49758</Property_ID><Risk>Medium</Risk><Locations><Location>Coastal</Location></Locations><Types><Type>Buy to let - Tourism</Type><Type>Buy to turn</Type><Type>Low deposit</Type></Types></Investment><Investment><Property_ID>63389</Property_ID><Risk>Medium</Risk><Locations><Location>Rural</Location></Locations><Types><Type>Buy to let - Residential</Type></Types></Investment><Investment><Property_ID>63390</Property_ID><Risk>Low</Risk><Locations><Location>Rural</Location></Locations><Types><Type>High rental yield</Type><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment><Property_ID>63548</Property_ID><Risk>Medium</Risk><Locations><Location>Mountain</Location></Locations><Types><Type>Holiday usage</Type></Types></Investment><Investment><Property_ID>63589</Property_ID><Risk>Medium</Risk><Locations><Location>Coastal</Location></Locations><Types><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment><Property_ID>64221</Property_ID><Risk>Low</Risk><Locations><Location>Mountain</Location><Location>Rural</Location></Locations><Types><Type>Buy to turn</Type><Type>Capital appreciation</Type><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment><Property_ID>64238</Property_ID><Risk>Low</Risk><Locations><Location>Rural</Location></Locations><Types><Type>Buy to turn</Type><Type>Capital appreciation</Type><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment><Property_ID>68956</Property_ID><Risk>Medium</Risk><Locations><Location>Rural</Location></Locations><Types><Type>High rental yield</Type><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment>

 

Anyone know why this is not working?

 

Cheers in advanced for your help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.