473,594 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the easiest way to import XML to MYSQL

What is the easiest way to import an XML Datafeed from a URL into a MYSQL
Database? Possibly using PHP

Regards Joe

PS Please answer to group and jo*@joesharman. co.uk

Jul 16 '05 #1
4 11435
Have a look at some of the PHP code written for handling Amazon.com's XML
based web services. The simplest code converts the XML data into an array
which is then used to build the required display pages.

My own demo associate site at http://retail.laughland.biz uses this method.

Once the data is in the array it is a simple matter to transfer it to a
database.

H G Laughland

http://www.laughland.biz
"the web site for web sites"

"J Sharman" <jo*@joesharman .co.uk> wrote in message
news:bf******** **@titan.btinte rnet.com...
What is the easiest way to import an XML Datafeed from a URL into a MYSQL
Database? Possibly using PHP

Regards Joe

PS Please answer to group and jo*@joesharman. co.uk

Jul 16 '05 #2
"J Sharman" <jo*@joesharman .co.uk> wrote in message news:<bf******* ***@titan.btint ernet.com>...
What is the easiest way to import an XML Datafeed from a URL into a MYSQL
Database? Possibly using PHP

Regards Joe

PS Please answer to group and jo*@joesharman. co.uk


I don't think there is an easy way. XML is like a freeform n-ary
tree, where each node has any number of children.

You could model that with some sort of node structure that
holds an array of pointers to all its children.

Alternately (and easier to implement with sql) you could model
nodes in an XML tree as relational tables where each
node (each table) holds a numerical
primary key plus a foreign key pointer to that node's parent.

Something like the following:

create table node
(
nid int primary key auto_increment, #pk for this node
rid int references node(nid),#poin ts to the root node of tree
pid int references node(nid),#poin ts to this node's parent
name VARCHAR(48) not null,
xpath VARCHAR(128), #the xpath to the node
value TEXT,
indexes(??)
)
For any database that really supports foreign keys,
you'd have trouble with the recusive node assigments
above: at least when you tried to initialize the root
node of a tree (real foreign keys have to point to
already existing keys).
So for Oracle or Postgres, you have to initialize the
table without the foreign key constraints, and
then add the fk attributes with an 'altertable'
command--after inserting the data.

Sql joins over a table like that are a nightmare, however.
The best solution is to forget about relational databases
and use a native XML database. Then you can query the tree
with XPath statements and/or XQuery, which were designed
with tree-like data in mind.
Jul 16 '05 #3
A long time ago, in a galaxy far, far away, "J Sharman" <jo*@joesharman .co.uk> wrote:
What is the easiest way to import an XML Datafeed from a URL into a MYSQL
Database? Possibly using PHP


Two choices:

1. Create a table looking like:

create table xml_feed (
url character varying;
xmlcontent character varying;
);

And basically treat the data as just plain, well, data.

You prepare a statement like:
insert into xml_feed (url, xmlcontent) values (?, ?);

Then execute it with the two values $URL and $XMLCONTENT.

(The point of the prepared statement is to avoid building up a query
where you'd have to escape special characters.)

2. Create some sort of tree hierarchy where each XML
element/attribute is set up as a separate record.

This would be painful _at best_ in a DBMS that gracefully supports
relational features like foreign keys, stored procedures, tree walking
or other such approaches to hierarchicalizi ng things, and such, and
probably not worth doing even WITH spectacular support for that sort
of thing.

But relational databases aren't terribly good at dealing with
pathologically hierarchical data, and that's what XML is.

So all that can be commended is approach #1.
--
wm(X,Y):-write(X),write( '@'),write(Y). wm('cbbrowne',' acm.org').
http://cbbrowne.com/info/xml.html
[Message From The Dover at MIT-AI 10:55:60]
HELP ME! HELP ME! MY PAPER FEED IS JAMMED! DO YOU KNOW WHAT IT'S LIKE TO
HAVE YOUR PAPER FEED JAMMED?
Jul 16 '05 #4
"J Sharman" <jo*@joesharman .co.uk> wrote in message
news:<bf******* ***@titan.btint ernet.com>...

What is the easiest way to import an XML Datafeed from a URL
into a MYSQL Database? Possibly using PHP


Easiest in terms of what -- ease of coding, use of memory,
execution time, something else? What are the dimensions of the
task -- 3 kb daily or 4 Mb per minute? How far along are you in
deciding how the XML should be mapped onto the database structure?
Is this a one-time task or a repetitive routine?

Here are a few options, just to get you started:

A. The memory-saving, but slow, one

Get one XML entity equivalent to a database record at a time,
parse, and insert. Say, you have an XML entity:

<event id="387629">
<date>2003-07-12</date>
<desc>This event cannot be adequately described</desc>
</event>

which can be mapped to a database query:

INSERT INTO events SET
id = 387629,
date = '2003-07-12',
desc = 'This event cannot be adequately described';

Running one query at a time will be slow because of the fixed
per-query overhead.

B. A faster one

Get a bunch of record equivalents at a time, parse them,
store the data as CSV, and then use LOAD DATA INFILE.
Using the <event> entity from the example above, you could
have a CSV file like this:

387629,"2003-07-12","This event cannot be adequately described"
387632,"2003-07-14","Just a non-descript event"
[more records like this]
786523,"2003-07-23","This is the last event"

MySQL will gladly (and VERY quickly) swallow this.

Here, the bottleneck will be writing records into the file.

C. A very fast (and memory-hungry) one

Get all record equivalents you want, parse them, and combine
the results into one monstrous query like this:

INSERT INTO events (id, date, desc) VALUES (
(387629,'2003-07-12','This event cannot be adequately described'),
(387632,'2003-07-14','Just a non-descript event'),
[more records like this]
(786523,'2003-07-23','This is the last event')
);

Everything wraps up in one query, but you risk running out of
memory if there is a lot of data. There is a workaround,
however; run the query every time the query string exceeds
certain length, and then begin to compose a new one.
Essentially, you'd be doing block writes...

Cheers,
NC
Jul 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3644
by: J Sharman | last post by:
What is the easiest way to import an XML Datafeed from a URL into a MYSQL Database? Possibly using PHP Regards Joe PS Please answer to group and joe@joesharman.co.uk
0
2011
by: Vidhya CS | last post by:
Hi , I am trying to export a database from one machine ie linux, and import the same database to another machine ie ,solaris . I exported the database using the following command . mysqldump -c -u vidhya ifmonitor > $HOME/ifmonito.backup. this is ok , ifmonitor-backup has the table creation info as well as the table data .
0
2147
by: adrian GREEMAN | last post by:
When I try to import a text file with new data for an existing table I get the error "1148 - the used command is not allowed with this MySQL version." I have tried with both PHPMyAdmin2.3 and with MySQLFront 2.5. Both these GUI programmes have an "import from text file" command which I have used successfully several times to add entries to this table before - running just this MySQL version. I have structured the data in the text...
7
9275
by: jj | last post by:
It's taking forever to upload 400,000 records to the database through access/odbc, and I've tried phpMyAdmin's interface but it seems to timeout during import of a CSV file. Is there a better way to import 400,000+ records?
8
31051
by: Johnny | last post by:
I was looking for information on how to import an excel file or other text file into a MySql database. I have done this with both access and SQL Server and am looking for a way to do this in MySql. I have several hundred items i want to import into a parts database that is currently in an excel file but can be saved as comma separated or other format. Any help would be greatly appreciated. Thanks in advance. Zach
1
2974
by: George Develekos | last post by:
I need to import into mysql data from DB2. One of the DB2 table columns is of the TIMESTAMP type, which, unlike its MySQL counterpart, supports fractions of a second, up to 6 digits, i.e. it is of the form 2005-07-13-23:45:32.000000 ....whereas the MySQL timestamp type is of the form 2005-07-13 23:45:32
7
33390
by: phillip.s.powell | last post by:
We're looking at a GUI interface for our MySQL DB and I am interested in MySQL Administrator, however, one of our requirements is to be able to import/export databases. Is this possible or do I need to know else (e.g. Navicat)? Thanks Phil
5
2735
by: Ryan Liu | last post by:
I have an application need export ane import data of projects. There are about 10 database tables releated to one project. 3 of them each could have up to 100K lines data. I can export all data out into a xml file and then zip it. When I do import, I parse this xml file and then insert into database myself. Or I can export all tables out in csv format and then use mysql's client command "load local file" (which is claimed very fast...
8
8807
by: Pierre Dagenais | last post by:
What is the easiest way to draw to a window? I'd like to draw something like sine waves from a mathematical equation. Newbie to python.
0
7880
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8255
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5413
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3868
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.