openerp-expert-framework team mailing list archive
-
openerp-expert-framework team
-
Mailing list archive
-
Message #00151
XML (de)serialization
About the improvements in XML, I'd like to propose a obj-to-vals (the
list/dict format suitable for write/create osv methods) and vals-to-xml
methods to osv.osv objects. The code developed by me with Dukai's help
is below.
http://paste-it.net/public/s29b2ca/
The methods are somewhat documented. Basically it converts the an
osv.osv object into a simple and human-friendly xml format.
For example, a res_partner object should give the expected output:
<customer>
<id>100</id>
<name>Cliente Teste</name>
<active>True</active>
<credit_limit>1000.00</credit_limit>
<address>
<item>
<id>150</id>
<name>José da Silva</name>
<type>default</type>
<stree1>Av. Goiás, 100, Ap 10</stree1>
<street2>Setor Central</street2>
<city>Goiânia</city>
<state_code>GO</state_code>
<country_code>BR</country_code>
<zip>74351018</zip>
<email>joao_silva@xxxxxxxxx</email>
<phone>62-5555-0000</phone>
<fax>62-5555-0001</fax>
<mobile>62-5555-0002</mobile>
</item>
</address>
</customer>
All you need is a very simple binding declaring what you want in your
xml. For the example above, you should provide:
binding = [
'id',
'name',
'active',
'credit_limit',
('address','address', [
'id',
'name',
'type',
'street',
'street2',
'city',
('state_id', 'state_code', 'code'),
('country_id', 'country_code', 'code'),
'zip',
'email',
'phone',
'fax',
'mobile'
]
)
]
By default, the serialization return a lxml object that can be further
customized in code. The deserialization method accepts either a xml
string or a lxml object so you can customize it prior to parsing.
Follow ups