Forum Moderators: coopster

Message Too Old, No Replies

Inserting XML File Contents into MySQL . . . ?

         

WebGyver

12:52 pm on Apr 15, 2008 (gmt 0)

10+ Year Member



Please forgive me if this has been answered elsewhere, but as of yet, I have not been able to find any solutions, links or mini-answers to this problem:

How do I insert the contents of an XML file into various fields of my MySQL table?

NOTE: I do not want to import the entire XML file into one column. Rather, I need to populate area code and phone number fields from an external XML file (changes monthly) into the corresponding columns in the MySQL table.

I must have tried a dozen different approaches, but I just can't get this to work.

By the way, this is an abbreviated XML sample:


<list type='full' level='state' val='UT'>
<ac val='435'>
<ph val='2000071' />
<ph val='2000072' />
<ph val='2000074' />
<ph val='2000075' />
<ph val='2000248' />
<ph val='2000280' />
<ph val='2001031' />
<ph val='2001032' />
<ph val='2002029' />
<ph val='2004309' />
<ph val='2006900' />
<ph val='9949900' />
<ph val='9949999' />
</ac>
<ac val='801'>
<ph val='2010000' />
<ph val='2010003' />
<ph val='2010004' />
<ph val='2010010' />
<ph val='2010011' />
<ph val='2010012' />
<ph val='2010014' />
<ph val='9998900' />
<ph val='9999999' />
</ac>
</list>

Any links or code snippets would be greatly appreciated.

eelixduppy

8:46 pm on Apr 15, 2008 (gmt 0)



Hello and Welcome to WebmasterWorld!

You'd have to go through the XML using SimpleXML or something similar, then construct your query or queries appropriately. Is it mandatory that you put the xml in the db? Maybe you can just read from the file?

WebGyver

8:51 pm on Apr 15, 2008 (gmt 0)

10+ Year Member



Thank you very much for your suggestions.

Yes, I did try the SimpleXML approach (a few times), but I must be doing something wrong.

The problem with searching through the entire file is its size: 25MB!

I'd rather get it into a database and query for specific phone numbers than loop through the file every time I need to find a black-listed phone number.

Thanks again.