Felipe Prenholato committed 54520bb

Add support to nillable objects, as in

Comments (0)

Files changed (2)

             self.qualified = 1
         #find and initialize imported ones
-        self.imported = [] 
+        self.imported = []
         imports = self.schema.findall('.//{%s}import' %xmlnamespace.NS_XSD)
         imports.extend(self.schema.findall('.//{%s}include' %xmlnamespace.NS_XSD))
         for schema in imports:
             Convert xml types definitions in the dictionary
             into Python classes.
             xtypes : dictionary name -> xml element
             out : dictionary name -> Python class
-        types = {} 
+        types = {}
         for k in xtypes:
             #if the class was already created as a parent of another class, do nothing
             if k in types:
                                   {"_children":[], "__doc__":"no documentation",
         types[name] = cls
     def create_string_enumeration(name, element, types):
                                 {"_allowedValues":values, "__doc__":doc,
         types[name] = cls
     def create_complex_class(name, element, xtypes, types):
         exts = element.findall("./{%s}complexContent/{%s}extension" %(xmlnamespace.NS_XSD, xmlnamespace.NS_XSD))
         if exts is not None:
             for ext in exts:
-                parent_name = ext.get("base", None) 
+                parent_name = ext.get("base", None)
                 parent = XMLSchemaParser.get_type_by_name(parent_name, xtypes, types)
                 maxOccurs = s.get('maxOccurs', 1)
                 if maxOccurs != 'unbounded':
                     maxOccurs = int(maxOccurs)
+                nillable = s.get('nillable', False) == 'true'
                 #child name is qualified as required, i.e. it is a full name
                 full_child_name = child_name
                 child_name = xmlnamespace.get_local_name(child_name) #class member names!
                     full_child_name = "{%s}%s" %(cls_ns, full_child_name)
                 children.append({ "name":child_name, 'type' : type,
                                  'min' : minOccurs, 'max' : maxOccurs,
+				                 'nillable': nillable,
                                  "fullname": full_child_name})
         #get doc
         doc = XMLSchemaParser.get_doc(element)
                 single.to_xml(element, full_child_name)
                 if child["type"] is XMLAny:
                     #append type information
-                    element[-1].set("{%s}type" %xmlnamespace.NS_XSI, 
+                    element[-1].set("{%s}type" %xmlnamespace.NS_XSI,
                             "{%s}%s" %(single._namespace,
                                        single.__class__.__name__) )
                     #single.to_xml(element, full_name)
                     #if child["type"] is XMLAny:
                         ##append type information
-                        #element[-1].set("{%s}type" %xmlnamespace.NS_XSI, 
+                        #element[-1].set("{%s}type" %xmlnamespace.NS_XSI,
                                 #"{%s}%s" %(single._namespace,
                                            #single.__class__.__name__) )
                 #except Exception:
             #check conversion
             if subvalue is None:
-                if self._children[ind]['min'] != 0:
+                if self._children[ind]['min'] != 0 and \
+                   self._children[ind]['nillable'] is False:
                     raise ValueError("Non-nillable %s element is nil." %name)
                 if self._children[ind]['max'].__class__.__name__ != "int" or\
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.