Link to home
Start Free TrialLog in
Avatar of cnermin
cnermin

asked on

xml to php

have some automatic way of reading XML in PHP or JScript etc.

XML example in the appendix...



I want to take this inportuje XML in MySQL. application was made in PHP
artikli.xml
Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia image

In PHP there is the SimpleXML library to handle XML ... is that what you want?

http://php.net/manual/en/book.simplexml.php
There are tons of method to read that XML with PHP and the  generic one is SimpleXML as lwadwell mentioned.

But the question is how do you like to store that in db. Do you have a specially created database for this xml or do you need to shape data which xml contains.

I guess you wish to import data -seems like a dealer integration data xml-
to your already used datafields. So you first need to map every data in xml to your database fields.

then pull xml data with any xml parser (SimpleXML is coming with PHP already) and then store them according to your mappings by iterating through xml data.

You need to care lots of things here  like
- what if that data already exists ? what action will be taken ? skip , overwrite or add another (you need to check for first and second one)
- Maybe you will need to update some portions of data for existing items.
- you may need to combine some input categories to one target category.
- etc.

So i wish you luck with these. If you need a specific help , we can help but as you can see this can not have a one line solution.
Avatar of cnermin
cnermin

ASKER

This is a mysql table ..

from this table is created in vb net xml, app, upload to FTP, then PHP should read xml and entries in mysql.
everything is ok just need PHP to read XML data from tables and insert into MySQL. I have several different tables this is an example of a table and XML


CREATE TABLE `artikli` (
  `art_broj` int(11) DEFAULT '0',
  `naziv` varchar(50) DEFAULT ' ',
  `cijena` decimal(18,2) DEFAULT '0.00',
  `tarifa` int(11) DEFAULT '0',
  `sank` int(11) DEFAULT '0',
  `kuhinja` int(11) DEFAULT '0',
  `SL` int(11) DEFAULT '0',
  `Alkohol` int(11) DEFAULT '0',
  `Bezalkohol` int(11) DEFAULT '0',
  `Ulcijenabezpdv` decimal(15,4) DEFAULT '0.0000',
  `Ulcijenasapdv` decimal(23,8) DEFAULT '0.00000000',
  `Minzalihe` decimal(10,0) DEFAULT '0',
  `Maxzalihe` decimal(10,0) DEFAULT '0',
  `Izcijenabezbdv` decimal(23,8) DEFAULT '0.00000000',
  `Izcijenasapdv` decimal(15,4) DEFAULT '0.0000',
  `Jedmjer` varchar(50) DEFAULT '0',
  `Tip` varchar(50) DEFAULT '0',
  `Stanje` decimal(15,4) DEFAULT '0.0000',
  `M1` decimal(15,4) DEFAULT '0.0000',
  `M2` decimal(15,4) DEFAULT '0.0000',
  `M3` decimal(15,4) DEFAULT '0.0000',
  `M4` decimal(15,4) DEFAULT '0.0000',
  `M5` decimal(15,4) DEFAULT '0.0000',
  `Kasa` int(11) DEFAULT '0',
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Art_Usl` int(11) DEFAULT '0',
  `NazivArtikla` varchar(50) DEFAULT '0',
  `Cigarete` int(11) DEFAULT '0',
  `Ostalo` int(11) DEFAULT '0',
  `Grupa` int(11) DEFAULT '0',
  `Ulaz` int(11) DEFAULT '0',
  `Slika` varchar(50) DEFAULT '0',
  `sanklista` int(11) DEFAULT '0',
  `lokacija` smallint(6) DEFAULT '0',
  `prsank` int(11) DEFAULT '0',
  `dusl` smallint(6) DEFAULT '0',
  `bar` varchar(50) DEFAULT '0',
  `novo` int(11) DEFAULT '0',
  `unic` varchar(50) DEFAULT '0',
  `cod` varchar(50) DEFAULT '0',
  `code` varchar(50) DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Reading XML and converting to an php object can be done like this ;
last line is just for debuging $data content..
            $kaynak = file_get_contents("ee-artikli.xml");
            $root   = simplexml_load_string($kaynak);
            $data   = get_object_vars($root);
            echo "<pre>";var_dump($data[$itemName][0]);echo "</pre>";

Open in new window


I think you can build your sql query syntax now
ASKER CERTIFIED SOLUTION
Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cnermin

ASKER

nice