Warning: count(): Parameter must be an array or an object that implements Countable in /home/luiscoms/www/blog/wp-includes/post-template.php on line 293

Warning: count(): Parameter must be an array or an object that implements Countable in /home/luiscoms/www/blog/wp-includes/post-template.php on line 293

Warning: count(): Parameter must be an array or an object that implements Countable in /home/luiscoms/www/blog/wp-includes/post-template.php on line 293

Warning: count(): Parameter must be an array or an object that implements Countable in /home/luiscoms/www/blog/wp-includes/post-template.php on line 293

Warning: count(): Parameter must be an array or an object that implements Countable in /home/luiscoms/www/blog/wp-includes/post-template.php on line 293
set
22
2014

Converter dicionário python para XML

Recentemente precisei criar um serviço em Python que retornasse JSON e XML.

No Python existe um tipo chamado dicionário (dict) que é o mais próximo de JSON e já possui uma classe específica para converte-lo. Até aí tudo bem, criei a estrutura em dict e já estava meio caminho andado.

Para o XML existem outras classes, mas teria que implementar a mesma lógica novamente e isso não me soou muito legal.

Pesquisando, achei alguns gists de uma função que convertem dict em XML porém ainda não era o que eu precisava.

Segue então o código completo que usei para minha solução baseado nos gists anterioriores.

Referências:

E você, já passou por uma situação parecida? Comenta aí!

Written by Luis com S in: Python | Tags:, , ,

Deixe um Comentário

Loading Disqus Comments ...
Loading Facebook Comments ...

Nenhum comentário »

RSS feed for comments on this post.


Leave a Reply


Time limit is exhausted. Please reload CAPTCHA.

Design: TheBuckmaker.com Web Templates