473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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*********@gmail.com>
Date: Mon, Jun 23, 2008 at 5:27 PM
Subject: xml to mysql (vice versa ) too
To: Py*********@python.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,create 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(node) :
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.minidom.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 1974
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*********@gmail.com>
Date: Mon, Jun 23, 2008 at 5:27 PM
Subject: xml to mysql (vice versa ) too
To: Py*********@python.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,create 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
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...
5
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...
5
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()...
0
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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...

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.