# HG changeset patch # User laurent # Date 1335796045 -7200 # Node ID bbffe4110141ad332627611c006ad3d04fcc14b4 # Parent b686f0081e2bc8ee818cf6224022032f2ed5d600 Fix bug in xmlclass with multiple choices in sequence diff -r b686f0081e2b -r bbffe4110141 xmlclass/xmlclass.py --- a/xmlclass/xmlclass.py Fri Apr 27 02:00:47 2012 +0200 +++ b/xmlclass/xmlclass.py Mon Apr 30 16:27:25 2012 +0200 @@ -726,13 +726,26 @@ element_idx = 0 while element_idx < len(value["value"]): for element_infos in infos["elements"]: - if element_infos["name"] == value["value"][element_idx]["name"]: - element_value = value["value"][element_idx]["value"] - element_idx += 1 + element_value = None + if element_infos["type"] == CHOICE: + choice_infos = None + if element_idx < len(value["value"]): + for choice in element_infos["choices"]: + if choice["name"] == value["value"][element_idx]["name"]: + choice_infos = choice + element_value = value["value"][element_idx]["value"] + element_idx += 1 + break + if ((choice_infos is not None and + not CheckElementValue(factory, choice_infos["name"], choice_infos, element_value, False)) or + (choice_infos is None and element_infos["minOccurs"] > 0)): + raise ValueError("Invalid sequence value in attribute 'content'") else: - element_value = None - if not CheckElementValue(factory, element_infos["name"], element_infos, element_value, False): - raise ValueError("Invalid sequence value in attribute 'content'") + if element_idx < len(value["value"]) and element_infos["name"] == value["value"][element_idx]["name"]: + element_value = value["value"][element_idx]["value"] + element_idx += 1 + if not CheckElementValue(factory, element_infos["name"], element_infos, element_value, False): + raise ValueError("Invalid sequence value in attribute 'content'") sequence_number += 1 if sequence_number < infos["minOccurs"] or infos["maxOccurs"] != "unbounded" and sequence_number > infos["maxOccurs"]: raise ValueError("Invalid sequence value in attribute 'content'") diff -r b686f0081e2b -r bbffe4110141 xmlclass/xsdschema.py --- a/xmlclass/xsdschema.py Fri Apr 27 02:00:47 2012 +0200 +++ b/xmlclass/xsdschema.py Mon Apr 30 16:27:25 2012 +0200 @@ -807,6 +807,10 @@ choices_tmp.append(choice) choices.extend(choices_tmp) + for choice in choices: + attributes["minOccurs"] = min(attributes["minOccurs"], choice["minOccurs"]) + choice["minOccurs"] = 1 + return {"type": CHOICE, "choices": choices, "minOccurs": attributes["minOccurs"], "maxOccurs": attributes["maxOccurs"], "doc": annotations}