1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| >>> import xmltodict
>>> dico = {
... "projet": "projet1",
... "identifiant": "X",
... "campagne": [
... {
... "nom": "campagne1",
... "identifiant": "XX",
... "iteration": [
... {
... "nom": "beta1",
... "identifiant": "XXX",
... "emploi": [
... {
... "nom": "emploi1",
... "propriete": [
... {
... "etape": "etape1",
... "motif": "renvoi"
... }
... ]
...
... },
... {
... "nom": "emploi2",
... "propriete": [
... {
... "etape": "etape2",
... "motif": "admis"
... }
... ]
... }
... ]
... }
... ]
... }
... ]
... }
...
>>> racine = { 'racine': dico }
>>> with open('result.xml', 'w') as f:
... print >> f, xmltodict.unparse(racine, pretty=True)
...
>>>
>>> _ = os.system('more result.xml')
<?xml version="1.0" encoding="utf-8"?>
<racine>
<projet>projet1</projet>
<campagne>
<nom>campagne1</nom>
<identifiant>XX</identifiant>
<iteration>
<emploi>
<nom>emploi1</nom>
<propriete>
<etape>etape1</etape>
<motif>renvoi</motif>
</propriete>
</emploi>
<emploi>
<nom>emploi2</nom>
<propriete>
<etape>etape2</etape>
<motif>admis</motif>
</propriete>
</emploi>
<nom>beta1</nom>
<identifiant>XXX</identifiant>
</iteration>
</campagne>
<identifiant>X</identifiant>
</racine>
>>> |
Partager