can anybody help me in this....This is not valid xml, there is no commas in attribute list in xml.
-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>
can somebody please help me......i am really confused!!!!!!You could try with minidom if your xml stream isn't too large, else sax parser
thanks in advance :)
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