diff --git a/process_includes.py b/process_includes.py index 7f074af2dfdc749fe741900451608262823bcade..05c386fed41e2c5e92f2c90bb4bc109d6489939c 100755 --- a/process_includes.py +++ b/process_includes.py @@ -33,8 +33,6 @@ from lxml import etree VERSION = '2.12a' ##VERSION## -Namespaces = {'xs': 'http://www.w3.org/2001/XMLSchema'} -Xsd_namespace_uri = 'http://www.w3.org/2001/XMLSchema' CatalogDict = {} # the base url to use for all relative paths in the catalog CatalogBaseUrl = None @@ -311,11 +309,14 @@ def prep_schema(inpath, outpath, options): def process_groups(root): + namespaces = {root.prefix: root.nsmap[root.prefix]} # Get all the xs:group definitions at top level. - defs = root.xpath('./xs:group', namespaces=Namespaces) + pattern = './%s:group' % (root.prefix, ) + defs = root.xpath(pattern, namespaces=namespaces) defs = [node for node in defs if node.get('name') is not None] # Get all the xs:group references (below top level). - refs = root.xpath('./*//xs:group', namespaces=Namespaces) + pattern = './*//%s:group' % (root.prefix, ) + refs = root.xpath(pattern, namespaces=namespaces) refs = [node for node in refs if node.get('ref') is not None] # Create a dictionary of the named model groups (definitions). def_dict = {} @@ -405,10 +406,13 @@ def replace_group_defs(def_dict, refs): if name is None: continue def_node = def_dict.get(name) + namespaces = {def_node.prefix: def_node.nsmap[def_node.prefix]} if def_node is not None: + pattern = './%s:sequence|./%s:choice|./%s:all' % ( + def_node.prefix, def_node.prefix, def_node.prefix, ) content = def_node.xpath( - './xs:sequence|./xs:choice|./xs:all', - namespaces=Namespaces) + pattern, + namespaces=namespaces) if content: content = content[0] parent = ref_node.getparent() @@ -449,7 +453,8 @@ def raise_anon_complextypes(root): else: pattern = './*/*//complexType|./*/*//simpleType' element_tag = 'element' - defs = root.xpath(pattern, namespaces=Namespaces) + namespaces = {prefix: root.nsmap[prefix]} + defs = root.xpath(pattern, namespaces=namespaces) for node in defs: parent = node.getparent() if parent.tag != element_tag: diff --git a/tests/attr_groups1_sup.py b/tests/attr_groups1_sup.py index d1db370b43c50ac8ffefef3fbdfa95bba6dd0c52..6ee84284491b8a7614c1ce836cf698bb236711c7 100644 --- a/tests/attr_groups1_sup.py +++ b/tests/attr_groups1_sup.py @@ -92,7 +92,10 @@ except ImportError, exp: def gds_format_string(self, input_data, input_name=''): return input_data def gds_validate_string(self, input_data, node, input_name=''): - return input_data + if not input_data: + return '' + else: + return input_data def gds_format_base64(self, input_data, input_name=''): return base64.b64encode(input_data) def gds_validate_base64(self, input_data, node, input_name=''): @@ -674,7 +677,7 @@ class GetUserReq(GeneratedsSuper): self.exportAttributes(outfile, level, already_processed, namespace_, name_='GetUserReq') if self.hasContent_(): outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespace_='', name_='GetUserReq', pretty_print=pretty_print) showIndent(outfile, level, pretty_print) outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) else: @@ -761,6 +764,7 @@ class GetUserReq(GeneratedsSuper): for child in node: nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] self.buildChildren(child, node, nodeName_) + return self def buildAttributes(self, node, attrs, already_processed): value = find_attr_value_('value04', node) if value is not None and 'value04' not in already_processed: diff --git a/tests/attr_groups2_sup.py b/tests/attr_groups2_sup.py index d1db370b43c50ac8ffefef3fbdfa95bba6dd0c52..6ee84284491b8a7614c1ce836cf698bb236711c7 100644 --- a/tests/attr_groups2_sup.py +++ b/tests/attr_groups2_sup.py @@ -92,7 +92,10 @@ except ImportError, exp: def gds_format_string(self, input_data, input_name=''): return input_data def gds_validate_string(self, input_data, node, input_name=''): - return input_data + if not input_data: + return '' + else: + return input_data def gds_format_base64(self, input_data, input_name=''): return base64.b64encode(input_data) def gds_validate_base64(self, input_data, node, input_name=''): @@ -674,7 +677,7 @@ class GetUserReq(GeneratedsSuper): self.exportAttributes(outfile, level, already_processed, namespace_, name_='GetUserReq') if self.hasContent_(): outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespace_='', name_='GetUserReq', pretty_print=pretty_print) showIndent(outfile, level, pretty_print) outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) else: @@ -761,6 +764,7 @@ class GetUserReq(GeneratedsSuper): for child in node: nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] self.buildChildren(child, node, nodeName_) + return self def buildAttributes(self, node, attrs, already_processed): value = find_attr_value_('value04', node) if value is not None and 'value04' not in already_processed: diff --git a/tests/simplecontent_restriction1_sup.py b/tests/simplecontent_restriction1_sup.py index 330b45ef46df545f56652af6ab5d5bd1cf02fd6c..74e903201ad896ca84e3800f5efda614a5c0e403 100644 --- a/tests/simplecontent_restriction1_sup.py +++ b/tests/simplecontent_restriction1_sup.py @@ -92,7 +92,10 @@ except ImportError, exp: def gds_format_string(self, input_data, input_name=''): return input_data def gds_validate_string(self, input_data, node, input_name=''): - return input_data + if not input_data: + return '' + else: + return input_data def gds_format_base64(self, input_data, input_name=''): return base64.b64encode(input_data) def gds_validate_base64(self, input_data, node, input_name=''): @@ -674,7 +677,7 @@ class IdentifierType(GeneratedsSuper): if self.hasContent_(): outfile.write('>') outfile.write(str(self.valueOf_).encode(ExternalEncoding)) - self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespace_='', name_='IdentifierType', pretty_print=pretty_print) outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) else: outfile.write('/>%s' % (eol_, )) @@ -752,6 +755,7 @@ class IdentifierType(GeneratedsSuper): for child in node: nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] self.buildChildren(child, node, nodeName_) + return self def buildAttributes(self, node, attrs, already_processed): value = find_attr_value_('schemeDataURI', node) if value is not None and 'schemeDataURI' not in already_processed: @@ -827,7 +831,7 @@ class BillOfResourcesIDType(IdentifierType): if self.hasContent_(): outfile.write('>') outfile.write(str(self.valueOf_).encode(ExternalEncoding)) - self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespace_='', name_='BillOfResourcesIDType', pretty_print=pretty_print) outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) else: outfile.write('/>%s' % (eol_, )) @@ -856,6 +860,7 @@ class BillOfResourcesIDType(IdentifierType): for child in node: nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] self.buildChildren(child, node, nodeName_) + return self def buildAttributes(self, node, attrs, already_processed): super(BillOfResourcesIDType, self).buildAttributes(node, attrs, already_processed) def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): @@ -900,7 +905,7 @@ class BillOfMaterialIDType(IdentifierType): if self.hasContent_(): outfile.write('>') outfile.write(str(self.valueOf_).encode(ExternalEncoding)) - self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespace_='', name_='BillOfMaterialIDType', pretty_print=pretty_print) outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) else: outfile.write('/>%s' % (eol_, )) @@ -929,6 +934,7 @@ class BillOfMaterialIDType(IdentifierType): for child in node: nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] self.buildChildren(child, node, nodeName_) + return self def buildAttributes(self, node, attrs, already_processed): super(BillOfMaterialIDType, self).buildAttributes(node, attrs, already_processed) def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): diff --git a/tests/simplecontent_restriction2_sup.py b/tests/simplecontent_restriction2_sup.py index 330b45ef46df545f56652af6ab5d5bd1cf02fd6c..74e903201ad896ca84e3800f5efda614a5c0e403 100644 --- a/tests/simplecontent_restriction2_sup.py +++ b/tests/simplecontent_restriction2_sup.py @@ -92,7 +92,10 @@ except ImportError, exp: def gds_format_string(self, input_data, input_name=''): return input_data def gds_validate_string(self, input_data, node, input_name=''): - return input_data + if not input_data: + return '' + else: + return input_data def gds_format_base64(self, input_data, input_name=''): return base64.b64encode(input_data) def gds_validate_base64(self, input_data, node, input_name=''): @@ -674,7 +677,7 @@ class IdentifierType(GeneratedsSuper): if self.hasContent_(): outfile.write('>') outfile.write(str(self.valueOf_).encode(ExternalEncoding)) - self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespace_='', name_='IdentifierType', pretty_print=pretty_print) outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) else: outfile.write('/>%s' % (eol_, )) @@ -752,6 +755,7 @@ class IdentifierType(GeneratedsSuper): for child in node: nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] self.buildChildren(child, node, nodeName_) + return self def buildAttributes(self, node, attrs, already_processed): value = find_attr_value_('schemeDataURI', node) if value is not None and 'schemeDataURI' not in already_processed: @@ -827,7 +831,7 @@ class BillOfResourcesIDType(IdentifierType): if self.hasContent_(): outfile.write('>') outfile.write(str(self.valueOf_).encode(ExternalEncoding)) - self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespace_='', name_='BillOfResourcesIDType', pretty_print=pretty_print) outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) else: outfile.write('/>%s' % (eol_, )) @@ -856,6 +860,7 @@ class BillOfResourcesIDType(IdentifierType): for child in node: nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] self.buildChildren(child, node, nodeName_) + return self def buildAttributes(self, node, attrs, already_processed): super(BillOfResourcesIDType, self).buildAttributes(node, attrs, already_processed) def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): @@ -900,7 +905,7 @@ class BillOfMaterialIDType(IdentifierType): if self.hasContent_(): outfile.write('>') outfile.write(str(self.valueOf_).encode(ExternalEncoding)) - self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespace_='', name_='BillOfMaterialIDType', pretty_print=pretty_print) outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) else: outfile.write('/>%s' % (eol_, )) @@ -929,6 +934,7 @@ class BillOfMaterialIDType(IdentifierType): for child in node: nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] self.buildChildren(child, node, nodeName_) + return self def buildAttributes(self, node, attrs, already_processed): super(BillOfMaterialIDType, self).buildAttributes(node, attrs, already_processed) def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):