Hello List,
I have a script to convert an XML document (containing new data for my database) into a bunch of SQL statements. (I didn't use XSL because I needed to make use of the already existing data in the database in order to do things like assign new id's to the data from the XML file...).
However, I'm having problems with it.
I have used a class, Record, to hold information on each new database record which will be created. It provides its functionality for three different types of record (a piece of music, a composer and a media item).
This confusion of identity is OK because the script is just a one-off. It is accomplished by using a 'type' property to identify the record's type (i.e. database table) and with all other properties being held in an array where the indexes are the field names.
When acting as a media item, one of its properties, 'details', takes its value from a number of different XML elements so I implemented an append($property, $value) method to complement the usual get and set methods which goes:
$this->properties[$property] .= "\n" . $value;
(Actually, it also takes into the cases where $value might be empty and where $this->properties[$property] might not yet be set.)
Now, the XML elements which feed into 'details' are all sub-elements of a 'recording' element and, whenever their 'endElement' event comes up (I'm using SAX to parse the docuemnt) I grab the data and call:
$media_item->append("details",$current_data)
The Record class provides a function to echo the resultant SQL statement which it does once each respective XML element ends. The objects are then unset() and the whole process loops over until the end of the XML.
The problem is that the $properties['details'] value of objects representing media items don't seem to want to let go of their old values and each resultant SQL insert statement for a media item has the all the 'details' values of its preceding media item SQL insert statements plus its own.
I've tried unsetting objects and $properties at every available opportunity in the script but nothing seems to make it work.
Any ideas?
Cheers,
rjl