473,835 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Fwd: xml to mysql (vice versa ) too

Le Tuesday 24 June 2008 07:08:46 swapna mudavath, vous avez écrit*:
can anybody help me in this....

-swapna

---------- Forwarded message ----------
From: swapna mudavath <sw*********@gm ail.com>
Date: Mon, Jun 23, 2008 at 5:27 PM
Subject: xml to mysql (vice versa ) too
To: Py*********@pyt hon.org
Hi,

I need to write a python script to store data which is in XML to MYSQL and
even vice versa....
what should be the approach?
i am able to establish a connection,crea te tables and insert data .....
but how to read an xml file and store in MYSQL....
my XML structure is like

<list title=" xyz", id = "1",....... .>
<item name=" abc" ,pos="1",...... ..>
</item>
<item name =" hgdf", pos ="3",......>
</item>
.
....
...
</list>
This is not valid xml, there is no commas in attribute list in xml.
can somebody please help me......i am really confused!!!!!!

thanks in advance :)
You could try with minidom if your xml stream isn't too large, else sax parser
is to be considered, but minidom is pretty easy to use.

Give it a try and come back with more specific questions.

In [82]: from xml.dom.minidom import parseString

In [83]: xml = """<list title=" xyz" id= "1">
<item name=" abc" pos="1">
</item>
<item name=" hgdf" pos ="3">
</item>
</list>"""

In [89]: def print_nodes(nod e) :
print node
if node.attributes :
for n, v in node.attributes .items() : print n, v
for i in node.childNodes : print_nodes(i)
....:
....:

In [94]: dom = parseString(xml )

In [95]: print_nodes(dom )
<xml.dom.minido m.Document instance at 0xc2b7e8>
<DOM Element: list at 0xc2b998>
id 1
title xyz
<DOM Text node "
">
<DOM Element: item at 0xc2bd40>
name abc
pos 1
<DOM Text node "
">
<DOM Text node "
">
<DOM Element: item at 0xc30050>
name hgdf
pos 3
<DOM Text node "
">
<DOM Text node "
">
--
_____________

Maric Michaud
Jun 27 '08 #1
1 2010
Le Tuesday 24 June 2008 07:08:46 swapna mudavath, vous avez écrit :
>can anybody help me in this....

-swapna

---------- Forwarded message ----------
From: swapna mudavath <sw*********@gm ail.com>
Date: Mon, Jun 23, 2008 at 5:27 PM
Subject: xml to mysql (vice versa ) too
To: Py*********@pyt hon.org
Hi,

I need to write a python script to store data which is in XML to MYSQL and
even vice versa....
what should be the approach?
i am able to establish a connection,crea te tables and insert data .....
but how to read an xml file and store in MYSQL....
my XML structure is like

<list title=" xyz", id = "1",....... .>
<item name=" abc" ,pos="1",...... ..>
</item>
<item name =" hgdf", pos ="3",......>
</item>
.
....
...
</list>

This is not valid xml, there is no commas in attribute list in xml.
Yes, so maybe you should tell us where you got this from and if you are in the
position to change this?

>can somebody please help me......i am really confused!!!!!!
Try lxml.objectify. It lets you work with XML as it if were simple Python objects.

http://codespeak.net/lxml/objectify.html

That should allow you to easily extract data from the XML and to generate XML
from the data you get from MySQL.

Stefan
Jun 27 '08 #2

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

Similar topics

2
2256
by: Ian Baker | last post by:
We have developed an Access/Jet database (2000, XP & 2003 versions) that has been used by clients all around the world for several years and is extremely robust with 55 tables, 172 hard stored queries (plus about the same in VBA SQL code), 60 forms and about 18,000 lines of code. The biggest advantage with Access is that it doesn't cost the client anything for if they don't have Access already then we provide the Runtime version which makes...
5
4578
by: news.telia.net | last post by:
Hi! I have a question. I have installed php and mysql on an apache-server on windows and I can't connect to the server. I tried to create a database (since I am trying to learn howto). My manual said I should write this at the shell: c:\mysql\bin>mysqladmin -u root creare mindb I did this and got this error:
5
11794
by: Bhoget | last post by:
Hello everyone, I successfully installed Php in IIS 5, but ran into a big problem in running MySql. I successfully installed MySql in my system but it does not show when I try to run phpinfo() although I have MySql running properly. I have uncommented the following lines in php.ini. --- extension=php_mysql.dll extension=php_mysqli.dll ---
0
864
by: marsmit | last post by:
Hey Guys, are you aware of anyone moving from MYSQL to MSSQL or vive versa - what were your experinces - Mark Smith
0
10808
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...
1
10560
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10233
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9344
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7766
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
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...
1
4433
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
2
3993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3088
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.