NYCPHP Meetup

NYPHP.org

[nycphp-talk] Translating XML to SQL

Dan Cech dcech at phpwerx.net
Wed Feb 11 14:13:07 EST 2004


 From the work I've done on adodb-xmlschema, I would advise an object 
oriented approach, it really helps to break up the logic.

I would create a class to hold the methods for parsing a document, etc, 
and another class to represent an article.

Once you have a class for the article you can build up all the article 
details from the xml, and finally generate and run the SQL to insert all 
the required records.  You could also use the class for accessing the 
data once it is in the database....

You may also want to create classes for author, etc which could handle 
the logic for updating/inserting the relevant details into those tables.

Anyway, it appears you are looking at a procedural solution right now, 
which will work too....honestly I'd have to have more details about the 
specific issues you are working around in order to give you any concrete 
advice.

Dan

Eric Rank wrote:
> I'm working on a PHP app that will translate XML to SQL based on a 
> configuration file with rules, and as I'm getting to the end of this 
> project, all the quirks and airbubbles (yes, ok, they're BUGS) are 
> getting squeezed out. And man, it's no fun. So now I'm looking for 
> solutions that may have been created before me.
>  
> Specifically, the xml contains information from articles in a newspaper. 
> Author, issue, volumne, section, category, headline, story, etc. This 
> xml we get from an export from QuarkXPress (which is its own nightmare)
>  
> I'm trying to  take this xml structure that contains NO database 
> specific information and place it into a MySQL database with about a 
> dozen related tables. The trick is that in going through an xml file, 
> there are a lot of contigencies to cover before finally reaching the 
> database. For example, some INSERT statements require the inserted id of 
> a previous insert statement in order to make the records relational (eg. 
> we need to insert the 'story' info into the 'article' table to get the 
> inserted id for the article, which then gets inserted into the 'photos' 
> table in the 'articleID' column.). Some insert statements might not need 
> to happen because the information already exists (eg. an author that 
> already exists in the database). You get the idea.
>  
> Anyone have experience doing this? Is there an open source project out 
> there that's working on this? Third party software even?
>  
> Thanks for your help,
>  
> Eric Rank




More information about the talk mailing list