dimanche 20 avril 2014

PyXB with XML schema containing choice statement


Vote count:

0




i am using pyXB for binding XML.


my schema used at there has choice elements.


so when i convert XML into a python instance


i don't know exactly which element is chosen at choice element.


So in order to distinguish, i have had to use if/else statement considering all cases.


for example, if the choice element has a and b, to distinguish one within a and b



A = binder.CreateFromDocument(xml) #bind into a python instance

#At this point, i don't know which element is included
#So I have to check using if/else
if A.a:
#processing in the case of a
A.a.aa = 'a'
else if A.b:
#processing in the case of b
A.b.bb = 'b'


the example is so simple and if/else looks enough but if the choice element has so many element about more than 100.


that processing(repeated if/else) will be so bad.


is there any other way to know which element is chosen?



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire