Jump to content

How do I put this basic xml into mysql database?


tommyda

Recommended Posts

I really have no clue whatsoever how to do this.

 

What I need to do is create a function to pull all email addresses from an external xml file then insert them into a database.

 

Example xml file

<?xml version="1.0"?>
<messenger>
  <service name=".NET Messenger Service">
    <contactlist>
      <contact type="1">[email protected]</contact>
      <contact type="1">[email protected]</contact>
      <contact type="1">[email protected]</contact>
      <contact type="1">[email protected]</contact>

    </contactlist>
  </service> 
</messenger>

 

If anyone can help me with the basics then that would be greatly appreciated.

 

Thanks

You can use this function to turn your XML input into an array:

 

http://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html

 

Then cycle through the values with a foreach loop and do what you need to do with them.

 

The output syntax used to access values in the array wasn't totally apparent to me at first - to save you some trouble, this is how you'd get at the email address in the first "contact" entry:

 

$yourArrayName['messenger']['_c']['service']['_c']['contactlist']['_c']['contact']['0']['_v']

 

You need to change ['0'] to ['1'] to get the next entry, and so on.

 

Hope that helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.