Hi,

I've tried on Stack, but without positive results, thus maybe someone here faced similar issue and can help:).

I would like to store XML results in DB. There are many tags (in example I only used two) in XML content, so instead of addressing every column's name explicitly, I iterate over returned XML's tags, check if name of tag equals name of the column -> if so, value for particular column is set.

The question is - how to deal with type? Do I have to convert content of XML's tag in |setattr| (if so - how to do it?) or sqlAlchemy does it automagically during insertion and I don't have to consider this issue?

Here is pseudo-code:

XML:

|<parts> <ident>DDFAGHFAA</ident> <value>-345.22098312</value> </parts>|

Python:

|class  MyModel(db.Model):

    prop_ident=  db.Column(db.String(20))
    prop_value=  db.Column(db.Float)

lxml_res=  xml_res.xpath(u'//parts')

mymodel_inst=  MyModel()

for  resin  lxml_res:

    if  hasattr(mymodel_inst,  (u'prop_'  +  res.tag).lower()):

        setattr(mymodel_inst,  (u'prop_'  +  res.tag).lower(),  res.text)|

I found that it can be accomplished using |isinstance| and type of column, but maybe there is simpler solution (or it is done by sqlAlchemy).

Cheers,
TomS
<http://stackoverflow.com/questions/4165143/easy-convert-betwen-sqlalchemy-columns-and-data-types>

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to