Process guide - XML

58 views
Skip to first unread message

Sayth Renshaw

unread,
Oct 31, 2013, 7:20:47 AM10/31/13
to sqlal...@googlegroups.com
Hi

Looking for some guidance using SQLAlchemy. In particular using SQLAlchemy to parse an XML file to the database.

I have read the docs in SQLAlchemy on creating database and classes and tables and then started reading http://docs.sqlalchemy.org/en/rel_0_9/orm/index.html?highlight=xml
However i want to understand the end process of importing the XML in and considerations and restrictions of this. Finding a lot of my search results are returning 'persisting xml' tutorials and examples, or very basic examples of typed in database entries (album, artist examples etc)

Can anyone help advise how I would go about this? Any tutorials or information appreciated. Have read tutorials on lxml and elementree as well but again I don't understand if SQLAlchemy needs me to parse via this first if so what is important to understand, or has SQLA another mechanism for handinling importing XML nodes to classes?

Thank you

Sayth

Simon King

unread,
Oct 31, 2013, 8:35:27 AM10/31/13
to sqlal...@googlegroups.com
SQLAlchemy itself doesn't really have any relationship at all with
XML, but in the source distribution, there are some examples of how
you might import data from an XML file into a database. See:

http://docs.sqlalchemy.org/en/latest/orm/examples.html#xml-persistence

and

https://bitbucket.org/zzzeek/sqlalchemy/src/eee219bc7e0656fb8afa9879bda799ab1d71b285/examples/elementtree?at=master

Which approach you follow really depends on how you are going to be
working with the data.

Hope that helps,

Simon

Sayth Renshaw

unread,
Oct 31, 2013, 4:17:01 PM10/31/13
to sqlal...@googlegroups.com


On Thursday, October 31, 2013, Simon King wrote:
--

Thanks Simon will have a look at these after work, I appreciate you taking the time to respond.

Sayth 

Burak Arslan

unread,
Oct 31, 2013, 4:44:22 PM10/31/13
to sqlal...@googlegroups.com
On 10/31/13 13:20, Sayth Renshaw wrote:
> Hi
>
> Looking for some guidance using SQLAlchemy. In particular using
> SQLAlchemy to parse an XML file to the database.

Do you want to map an xml schema to a database schema, or you just are
looking for advice on how to put the xml blob on a database?

If the former, http://spyne.io/#s=sql&ser=Xml&show=Schema and
http://spyne.io/docs/2.10/reference/util.html#spyne.util.xml.get_xml_as_object
could help you get started.

This way, you can persist an xml document efficiently in a relational
database (numbers go to an int column, etc.)

For the latter, Spyne has a PGXml type that saves an lxml.etree.Element
instance to the xml column in a postgres database.

https://github.com/arskom/spyne/blob/2_10/spyne/util/sqlalchemy.py#L196

Hope it helps.

Best,
Burak
Reply all
Reply to author
Forward
0 new messages