We help IT Professionals succeed at work.

PHP Script to import XML File

softbless
softbless asked
on
Hi Guys,

I need PHP script that :
# There is a form to upload an XML file
# After that importing that XML to a table in MySQL
# Show success message when it's done importing the XML file, and give error message when it's failed to import

To help you setting the table, I give you the SQL script to create the table, and I also attach XML file sample.
 sample.xml

Please help. Thanks
/*
SQLyog Community Edition- MySQL GUI v7.11 
MySQL - 5.0.67-community : Database - sementara
*********************************************************************
*/


/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

CREATE DATABASE /*!32312 IF NOT EXISTS*/`temporary` /*!40100 DEFAULT CHARACTER SET latin1 */;

/*Table structure for table `catalog` */

DROP TABLE IF EXISTS `catalog`;

CREATE TABLE `catalog` (
  `File_Name` varchar(1000) default NULL,
  `Category` varchar(1000) default NULL,
  `modified_date` varchar(1000) default NULL,
  `location` varchar(1000) default NULL,
  `size` varchar(1000) default NULL,
  `Content_type` varchar(1000) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*Data for the table `catalog` */

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

Open in new window

Comment
Watch Question

Freelancer
Top Expert 2010
Commented:
Once you have stored xml file uploaded you have to use SimpleXML to retrieve nodes values. Take a look here http://it.php.net/manual/en/book.simplexml.php.
With  SimpleXML you can access any xml file and read all its values storing them in an array. With this you can show messages:

$xml = simplexml_load_string($yourfileuploaded) or die ('Error importing xml file.');

Then it's very simple execute any query you wish.

Hope this helps

Author

Commented:
Thanks for helping