Import an XML file into MySql using PHP

joshua.howell - March 28, 2008 - 00:10

The business i work for have a real estate database that exports XML files to other large real estate websites but also exports generic XML files which we would like to use to populate and update our Drupal website which uses the rListing module. Apparently an XML file is generated for each property along with copies of jpegs which is then packaged into a zip file (one zip for each property). I don't know how to write PHP or MySQL from scatch but i am able to modify working examples to a certain extent, so where should i start in trying to accomplish this? From what i have read, the first part involves turning the XML data into an array and the second part would involve inserting the data into the appropriate tables. I also read that SimpleXML function might be usable. A new XML file will be generated each time a new property is created or an existing one is updated so it would be great if i could automate this process somehow, maybe with a cron job?

This is a sample of the XML file layout;

<!-- Contact Details -->
<!ELEMENT Contact ( ContactName,
BHPhone?,
AHPhone?,
Mobile?,
Email?,
UpdateStatus,
UpdateTime )>

<!ATTLIST Contact ContactID CDATA #REQUIRED >
<!ELEMENT ContactName ( #PCDATA ) >
<!ELEMENT BHPhone ( #PCDATA ) >
<!ELEMENT AHPhone ( #PCDATA ) >
<!ELEMENT Mobile ( #PCDATA ) >
<!ELEMENT Email ( #PCDATA ) >

<!-- Property Details -->
<!ELEMENT Property ( ListingType?,
SaleAuthority?,
StreetNumber?,
StreetName?,
Suburb?,
Postcode?,
State?,
Municipality?,
EstateName?,
EstateStage?,
Zone?,
StreetDirectory?,
MapPage?,
MapReference?,
AddressDisplayType?,
BuildingType?,
PropertyType?,
LandFrontage?,
LandWidthRear?,
LandDepthLeft?,
LandDepthRight?,
LandCrossover?,
LandArea?,
BuildingArea?,
NewlyBuilt?,
Rent?,
RentPeriod?,
DateAvailable?,
SalePrice?,
PriceView?,
DisplayPrice?,
Outgoings?,
CommReturn?,
LeaseEndDate?,
AuctionDate?,
AuctionLocation?,
UnderOffer?,
SoldPrice?,
SoldDate?,
AdvHeading?,
AdvDescription?,
AdvNotes?,
ContactID?,
Features?,
Inspections?,
ExternalLinks?,
Images?,
UpdateStatus,
UpdateTime )>
<!ATTLIST Property PropertyID CDATA #REQUIRED >

<!-- Listing -->
<!ELEMENT ListingType EMPTY >
<!ATTLIST ListingType Type ( Rent |
Sale ) #REQUIRED >
<!ELEMENT SaleAuthority EMPTY > <!-- Sale Only -->
<!ATTLIST SaleAuthority Type ( Auction |
Sale |
Exclusive |
Multilist |
Conjunction |
Open |
Tender |
EOI ) #REQUIRED >

<!-- Address -->
<!ELEMENT StreetNumber ( #PCDATA ) >
<!ELEMENT StreetName ( #PCDATA ) >
<!ELEMENT Suburb ( #PCDATA ) >
<!ELEMENT Postcode ( #PCDATA ) >
<!ELEMENT State ( #PCDATA ) >
<!ELEMENT Municipality ( #PCDATA ) > <!-- Sale Only -->
<!ELEMENT EstateName ( #PCDATA ) > <!-- Sale Only -->
<!ELEMENT EstateStage ( #PCDATA ) > <!-- Sale Only -->
<!ELEMENT Zone ( #PCDATA ) > <!-- Sale Only -->

Could anyone explain the process involvement in terms a newbie would understand, supply a piece of code to get started with or maybe point me to something existing which might work? I think this job is above my current skill level but would like to give it a try before outsourcing it so any help would be great.

Thank you,

Joshua Howell

Does anyone know if it's

joshua.howell - March 31, 2008 - 21:41

Does anyone know if it's even possible to import XML data into a MySQL database using PHP?

Could someone please suggest

joshua.howell - April 15, 2008 - 23:18

Could someone please suggest a starting point? Perhaps a module which parses XML? Anything?

 
 

Drupal is a registered trademark of Dries Buytaert.